|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Tkinter AttributeError: Entry has no __call__ method
This has got me stumped for the last 2 days, someone please help!!
I am creating a GUI interface and I keep getting this error when I press the "New" button (self.buttonNew) AttributeError: Entry has no __call__ method here's the code, can anyone help? Code:
#!/usr/bin/python from Tkinter import * class MAINGUI(Frame): def __init__ (self, parent): ######################################### # Compose Frames and Subframes # ######################################### self.myParent = parent self.mainFrame = Frame(parent) self.mainFrame.pack(expand=NO, fill=BOTH) self.subFrame1 = Frame(self.mainFrame, bg=frame1_bg) self.subFrame1.pack(expand=YES, fill=BOTH) self.subFrame2 = Frame(self.mainFrame, relief=RIDGE, borderwidth=3, bg=frame2_bg) self.subFrame2.pack(expand=YES, fill=BOTH) ######################################### # Buttons # ######################################### self.buttonNew = Button(self.subFrame1, text='New', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=NORMAL, command=self.clickNew) self.buttonNew.grid(column=0, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonSave = Button(self.subFrame1, text='Save', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED) self.buttonSave.grid(column=1, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonSearch = Button(self.subFrame1, text='Search', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=NORMAL) self.buttonSearch.grid(column=2, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonEdit = Button(self.subFrame1, text='Edit', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED) self.buttonEdit.grid(column=3, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonCalc = Button(self.subFrame1, text='Calculate', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED, command=self.clickCalc) self.buttonCalc.grid(column=4, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonPrint = Button(self.subFrame1, text='Print', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED, command=self.clickPrint) self.buttonPrint.grid(column=5, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonQuit = Button(self.subFrame1, text='Quit', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, command=self.clickQuit) self.buttonQuit.grid(column=6, row=0, ipadx=button_ipadx, pady=button_pady) ################################################# # Source Analysis Labels and Entry's # ################################################# self.labelSourcenumber = Label(self.subFrame2, text="Source Number", bg=label_bg, fg=label_fg) self.labelSourcenumber.grid(column=0, row=0, sticky=W, pady=label_pady) self.entrySourcenumber = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entrySourcenumber.grid(column=1, row=0, pady=entry_pady) self.labelChecksource = Label(self.subFrame2, text="Check Source", bg=label_bg, fg=label_fg) self.labelChecksource.grid(column=0, row=1, sticky=W, pady=label_pady) self.entryChecksource = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryChecksource.grid(column=1, row=1, pady=entry_pady) self.labelBkgcount = Label(self.subFrame2, text="Background Count", bg=label_bg, fg=label_fg) self.labelBkgcount.grid(column=2, row=1, sticky=W, pady=label_pady) self.entryBkgcount = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryBkgcount.grid(column=3, row=1, pady=entry_pady) self.labelWipecount = Label(self.subFrame2, text="Wipe Count", bg=label_bg, fg=label_fg) self.labelWipecount.grid(column=4, row=1, sticky=W, pady=label_pady) self.entryWipecount = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryWipecount.grid(column=5, row=1, pady=entry_pady) self.labelResult = Label(self.subFrame2, text="Result", bg=label_bg, fg=label_fg) self.labelResult.grid(column=6, row=1, sticky=W, pady=label_pady) self.entryResult = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryResult.grid(column=7, row=1, pady=entry_pady) def clickQuit(self): self.myParent.destroy() def clickCalc(self): self.buttonQuit.configure(state=DISABLED) def clickPrint(self): self.buttonQuit.configure(state=NORMAL) def clickNew(self): self.frame2Enable() def frame2Disable2(): self.entrySourcenumber(state=DISABLED) self.entryChecksource(state=DISABLED) self.entryBkgcount(state=DISABLED) self.entryWipecount(state=DISABLED) self.entryResult(state=DISABLED) def frame2Enable(self): self.entrySourcenumber(state=NORMAL) self.entryChecksource(state=NORMAL) self.entryBkgcount(state=NORMAL) self.entryWipecount(state=NORMAL) self.Result(state=NORMAL) root = Tk() MainGUI = MAINGUI(root) root.mainloop() Last edited by netytan : February 5th, 2004 at 04:33 PM. |
|
#2
|
||||
|
||||
|
Hi smith,
the problem sees to be that self.clickNew isnt callable, because it doesnt exist anywhere in the code you posted I dont know what happened to when you posted your code but adding [ CODE ]...[/ CODE ] tags didnt fix it. And Indentation being VERY important to Python its VERY important that you make sure the code you post is intended correctly ![]() Take care, Mark. |
|
#3
|
|||
|
|||
|
Updated indented code
Sorry for not using
Code:
... Here's the indented code for easier reading. Your right, I figured out that the code ISN'T callable, but how do you actually make the functions inside the class callable to inside class code or even outside the class code - what C++ would refer to as "private" or "public". Code:
#!/usr/bin/python from Tkinter import * class MAINGUI(Frame): def __init__ (self, parent): ######################################### # Compose Frames and Subframes # ######################################### self.myParent = parent self.mainFrame = Frame(parent) self.mainFrame.pack(expand=NO, fill=BOTH) self.subFrame1 = Frame(self.mainFrame, bg=frame1_bg) self.subFrame1.pack(expand=YES, fill=BOTH) self.subFrame2 = Frame(self.mainFrame, relief=RIDGE, borderwidth=3, bg=frame2_bg) self.subFrame2.pack(expand=YES, fill=BOTH) ######################################### # Buttons # ######################################### self.buttonNew = Button(self.subFrame1, text='New', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=NORMAL, command=self.clickNew) self.buttonNew.grid(column=0, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonSave = Button(self.subFrame1, text='Save', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED) self.buttonSave.grid(column=1, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonSearch = Button(self.subFrame1, text='Search', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=NORMAL) self.buttonSearch.grid(column=2, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonEdit = Button(self.subFrame1, text='Edit', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED) self.buttonEdit.grid(column=3, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonCalc = Button(self.subFrame1, text='Calculate', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED, command=self.clickCalc) self.buttonCalc.grid(column=4, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonPrint = Button(self.subFrame1, text='Print', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, state=DISABLED, command=self.clickPrint) self.buttonPrint.grid(column=5, row=0, ipadx=button_ipadx, pady=button_pady) self.buttonQuit = Button(self.subFrame1, text='Quit', height=button_height, width=button_width, \ bg=button_bg, fg=button_fg, command=self.clickQuit) self.buttonQuit.grid(column=6, row=0, ipadx=button_ipadx, pady=button_pady) ################################################# # Source Analysis Labels and Entry's # ################################################# self.labelSourcenumber = Label(self.subFrame2, text="Source Number", bg=label_bg, fg=label_fg) self.labelSourcenumber.grid(column=0, row=0, sticky=W, pady=label_pady) self.entrySourcenumber = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entrySourcenumber.grid(column=1, row=0, pady=entry_pady) self.labelChecksource = Label(self.subFrame2, text="Check Source", bg=label_bg, fg=label_fg) self.labelChecksource.grid(column=0, row=1, sticky=W, pady=label_pady) self.entryChecksource = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryChecksource.grid(column=1, row=1, pady=entry_pady) self.labelBkgcount = Label(self.subFrame2, text="Background Count", bg=label_bg, fg=label_fg) self.labelBkgcount.grid(column=2, row=1, sticky=W, pady=label_pady) self.entryBkgcount = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryBkgcount.grid(column=3, row=1, pady=entry_pady) self.labelWipecount = Label(self.subFrame2, text="Wipe Count", bg=label_bg, fg=label_fg) self.labelWipecount.grid(column=4, row=1, sticky=W, pady=label_pady) self.entryWipecount = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryWipecount.grid(column=5, row=1, pady=entry_pady) self.labelResult = Label(self.subFrame2, text="Result", bg=label_bg, fg=label_fg) self.labelResult.grid(column=6, row=1, sticky=W, pady=label_pady) self.entryResult = Entry(self.subFrame2, width=entry_width, state=DISABLED) self.entryResult.grid(column=7, row=1, pady=entry_pady) def clickQuit(self): self.myParent.destroy() def clickCalc(self): self.buttonQuit.configure(state=DISABLED) def clickPrint(self): self.buttonQuit.configure(state=NORMAL) def clickNew(self): self.frame2Enable() def frame2Disable2(): self.entrySourcenumber(state=DISABLED) self.entryChecksource(state=DISABLED) self.entryBkgcount(state=DISABLED) self.entryWipecount(state=DISABLED) self.entryResult(state=DISABLED) def frame2Enable(self): self.entrySourcenumber(state=NORMAL) self.entryChecksource(state=NORMAL) self.entryBkgcount(state=NORMAL) self.entryWipecount(state=NORMAL) self.Result(state=NORMAL) root = Tk() MainGUI = MAINGUI(root) root.mainloop() |
|
#4
|
||||
|
||||
|
Thanks, that helped alot!
Anyway i've managed to trace you're error back to the frame2Enable() method. And the reason for the error is that your trying to alter the arguments in your Entry() boxes after they've been called and assigned to variables i.e. Code:
>>> class someclass:
... def __init__(self, args): self.args = args
...
>>> instance = someclass('argument')
>>> instance('altering')
Traceback (most recent call last):
File "<input>", line 1, in ?
AttributeError: someclass instance has no __call__ method
>>>
Try changing this function to read. However i havnt tested this and to be honest i've never had to change a argument after calling. Bu then i'm not really a big GUI fan anyway ![]() Code:
def frame2Enable(self): self.entrySourcenumber.state=NORMAL self.entryChecksource.state=NORMAL self.entryBkgcount.state=NORMAL self.entryWipecount.state=NORMAL self.Result.state=NORMAL Mark. |
|
#5
|
||||
|
||||
|
Hi mistersmith,
Normally you would call a widgets config method to change things. So (untested ):Code:
def frame2Enable(self): self.entrySourcenumber.config(state=NORMAL) self.entryChecksource.config(state=NORMAL) self.entryBkgcount.config(state=NORMAL) self.entryWipecount.config(state=NORMAL) self.Result.config(state=NORMAL) You may also have to call self.mainFrame.update() to force the refresh. Cheers, Grim |
|
#6
|
|||
|
|||
|
Incredible.
So, this is what's been killing me for the last 3 days? The .config worked - many many thanks for replying and helping me out. Cheers, Jeff |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Tkinter AttributeError: Entry has no __call__ method |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|