Reputation: 373
First, all relevant code
main.py
import string
import app
group1=[ "spc", "bspc",",","."]#letters, space, backspace(spans mult layers)
# add in letters one at a time
for s in string.ascii_lowercase:
group1.append(s)
group2=[0,1,2,3,4,5,6,7,8,9, "tab ","ent","lAR" ,"rAR" , "uAR", "dAR"]
group3= []
for s in string.punctuation:
group3.append(s)#punc(spans mult layers)
group4=["copy","cut","paste","save","print","cmdW","quit","alf","sWDW"] #kb shortcut
masterGroup=[group1,group2,group3,group4]
myApp =app({"testFKey":[3,2,2]})
app.py
import tkinter as tk
import static_keys
import dynamic_keys
import key_labels
class app(tk.Frame):
def __init__(inputDict,self, master=None,):
tk.Frame.__init__(self, master)
self.grid(sticky=tk.N+tk.S+tk.E+tk.W)
self.createWidgets(self, inputDict)
def createWidgets(self,inDict):
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
tempDict = {}
for k,v in inDict.items():
if 1<=v[0]<=3:
tempDict[k] = static_keys(*v[1:])
elif v[0] ==4:
tempDict[k] = dynamic_keys(k,*v[1:])
elif v[0]==5:
tempDict[k] = key_labels(*v[1:])
for o in tempDict:
tempDict[o].grid()
return tempDict
static_keys.py
import tkinter
class static_keys(tkinter.Label):
"""class for all keys that just are initiated then do nothing
there are 3 options
1= modifier (shift etc)
2 = layer
3 = fkey, eject/esc"""
def __init__(t,selector,r,c,parent,self ):
if selector == 1:
tkinter.Label.__init__(master=parent, row=r, column=c, text= t, bg ='#676731')
if selector == 2:
tkinter.Label.__init__(master=parent, row=r, column=c, text= t, bg ='#1A6837')
if selector == 3:
tkinter.Label.__init__(master=parent, row=r, column=c, text= t, bg ='#6B6966')
Now for a description of the problem. When I run main.py
in python3, I get the error
File "Desktop/kblMaker/main.py", line 13, in <module>
myApp =app({"testFKey":[3,2,2]})
TypeError: 'module' object is not callable
Upvotes: 12
Views: 56790
Reputation: 459
The best way to fix this problem is: Go to Gradle, build
(Madulus) and below the buildTypes
, type the following code and sync the project.
viewBinding {
enabled = true
}
Now you can access to the binding. If the xml layout is activity_main.xml
, it means the binding is ActivityMainBinding
.
Upvotes: 0
Reputation: 365657
The problem, as both F.J and Tadeck already explained, is that app
is the module app
, and app.app
is the class app
defined in that module.
You can get around that by using from app import app
(or, if you must, even from app import *
), as in Tadeck's answer, or by explicitly referring to app.app
instead of just app
, as in F.J's answer.
If you rename the class to App
, that won't magically fix anything—you will still have to either from app import App
or refer to app.App
—but it will make the problem a whole lot more obvious. And make your code less confusing after you've fixed the problem, too.
This is part of the reason that PEP 8 recommends that:
Modules should have short, all-lowercase names.
…
Almost without exception, class names use the CapWords convention.
That way, there's no way to mix them up.
Upvotes: 2
Reputation: 208425
You have a module named app
that contains a class named app
. If you just do import app
in main.py then app
will refer to the module, and app.app
will refer to the class. Here are a couple of options:
myApp = app.app({"testFKey":[3,2,2]})
inside of main.pyimport app
with from app import app
, now app
will refer to the class and myApp = app({"testFKey":[3,2,2]})
will work fineUpvotes: 33
Reputation: 137310
In main.py
change second line to:
from app import app
The issue is you have app
module and app
class within it. But you are importing module, not the class from it:
myApp = app({"testFKey": [3, 2, 2]})
(you can also instead replace "app
" inside line above into "app.app
")
Upvotes: 10