in the following program i want "1" to appear in the upper "entry" when i click the button "1".
so i will replace state=DISBALED with command=self.Display(xbtn) or command=Display(xbtn). Display being a function that takes the pressed buttons "value" and so outputs in the first entry the corresponding integer or arithmetic. ive tried this but i dont get ti to work. is Display some sort of predefined function that im f***ing around with? 2nd code is the implementation of the Display-funcand corresponding errormessages. what is the problem here? #! /usr/bin/env python from Tkinter import * import tkMessageBox class GUIFramework(Frame): """This is the GUI""" def __init__(self,master=None): """Initialize yourself""" """Initialise the base class""" Frame.__init__(self,master) """Set the Window Title""" self.master.title("Calculator") """Display the main window" with a little bit of padding""" self.grid(padx=10,pady=10) self.CreateWidgets() def CreateWidgets(self): self.btnDisplay = Button(self, text="1", state=DISABLED) self.btnDisplay.grid(row=0, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="2", state=DISABLED) self.btnDisplay.grid(row=0, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="3", state=DISABLED) self.btnDisplay.grid(row=0, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="+", state=DISABLED) self.btnDisplay.grid(row=0, column=3, padx=5, pady=5) self.btnDisplay = Button(self, text="4", state=DISABLED) self.btnDisplay.grid(row=1, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="5", state=DISABLED) self.btnDisplay.grid(row=1, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="6", state=DISABLED) self.btnDisplay.grid(row=1, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="-", state=DISABLED) self.btnDisplay.grid(row=1, column=3, padx=5, pady=5) self.btnDisplay = Button(self, text="7", state=DISABLED) self.btnDisplay.grid(row=2, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="8", state=DISABLED) self.btnDisplay.grid(row=2, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="9", state=DISABLED) self.btnDisplay.grid(row=2, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="*", state=DISABLED) self.btnDisplay.grid(row=2, column=3, padx=5, pady=5) self.btnDisplay = Button(self, text="0", state=DISABLED) self.btnDisplay.grid(row=3, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="C", state=DISABLED) self.btnDisplay.grid(row=3, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="r", state=DISABLED) self.btnDisplay.grid(row=3, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="/", state=DISABLED) self.btnDisplay.grid(row=3, column=3, padx=5, pady=5) #def Display(self): if __name__ == "__main__": guiFrame = GUIFramework() guiFrame.mainloop() #! /usr/bin/env python from Tkinter import * import tkMessageBox class GUIFramework(Frame): """This is the GUI""" def __init__(self,master=None): """Initialize yourself""" """Initialise the base class""" Frame.__init__(self,master) """Set the Window Title""" self.master.title("Calculator") """Display the main window" with a little bit of padding""" self.grid(padx=10,pady=10) self.CreateWidgets() def CreateWidgets(self): #self.pack_propagate(0) self.enText = Entry(self) self.enText.grid(row=0, column=0, columnspan=8, padx=5, pady=5) self.enText = Entry(self) self.enText.grid(row=1, column=0, columnspan=8, padx=5, pady=5) self.btnDisplay = Button(self, text="1", command=Display('1')) self.btnDisplay.grid(row=3, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="2", state=DISABLED) self.btnDisplay.grid(row=3, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="3", state=DISABLED) self.btnDisplay.grid(row=3, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="+", state=DISABLED) self.btnDisplay.grid(row=3, column=3, padx=5, pady=5) self.btnDisplay = Button(self, text="4", state=DISABLED) self.btnDisplay.grid(row=4, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="5", state=DISABLED) self.btnDisplay.grid(row=4, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="6", state=DISABLED) self.btnDisplay.grid(row=4, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="-", state=DISABLED) self.btnDisplay.grid(row=4, column=3, padx=5, pady=5) self.btnDisplay = Button(self, text="7", state=DISABLED) self.btnDisplay.grid(row=5, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="8", state=DISABLED) self.btnDisplay.grid(row=5, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="9", state=DISABLED) self.btnDisplay.grid(row=5, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="*", state=DISABLED) self.btnDisplay.grid(row=5, column=3, padx=5, pady=5) self.btnDisplay = Button(self, text="0", state=DISABLED) self.btnDisplay.grid(row=6, column=0, padx=5, pady=5) self.btnDisplay = Button(self, text="C", state=DISABLED) self.btnDisplay.grid(row=6, column=1, padx=5, pady=5) self.btnDisplay = Button(self, text="r", state=DISABLED) self.btnDisplay.grid(row=6, column=2, padx=5, pady=5) self.btnDisplay = Button(self, text="/", state=DISABLED) self.btnDisplay.grid(row=6, column=3, padx=5, pady=5) #self.btnDisplay.pack(fill=BOTH, expand=1) def Display(xbtn): if xbtn==1: print 1 if __name__ == "__main__": guiFrame = GUIFramework() guiFrame.mainloop() command=self.Display(xbtn) Traceback (most recent call last): File "C:/Users/saftarn/Desktop/guiexperiments/defdonka.py", line 87, in <module> guiFrame = GUIFramework() File "C:/Users/saftarn/Desktop/guiexperiments/defdonka.py", line 20, in __init__ self.CreateWidgets() File "C:/Users/saftarn/Desktop/guiexperiments/defdonka.py", line 33, in CreateWidgets self.btnDisplay = Button(self, text="1", command=self.Display('1')) TypeError: Display() takes exactly 1 argument (2 given) command=Display(xbtn) Traceback (most recent call last): File "C:/Users/saftarn/Desktop/guiexperiments/defdonka.py", line 87, in <module> guiFrame = GUIFramework() File "C:/Users/saftarn/Desktop/guiexperiments/defdonka.py", line 20, in __init__ self.CreateWidgets() File "C:/Users/saftarn/Desktop/guiexperiments/defdonka.py", line 33, in CreateWidgets self.btnDisplay = Button(self, text="1", command=Display('1')) NameError: global name 'Display' is not defined -- View this message in context: http://www.nabble.com/Buttonwidget%2C-problem-with-callback-function%21--tp16508071p16508071.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss