-1

I have 3 entries on my window currently that contain a particular variable. And my goal is to be able to type something within thosse entries then press a button to update them all and run a command. However the command I set my button to run for some reason gets automatically ran as soon as you start the program and then becomes unusable. Here's the part of my code that presents an issue currently buttonA is the one with the command.

#Entries
entryA = Entry(Window,text="Angle",bg=bgB,fg=fgB,bd=0)
entryA.grid(row=1,column=2)
entryA.insert(0,info['a'])
entryB = Entry(Window,text="Velocity",bg=bgB,fg=fgB,bd=0)
entryB.grid(row=2,column=2)
entryB.insert(0,info['v'])
entryC = Entry(Window,text="Initial Height",bg=bgB,fg=fgB,bd=0)
entryC.grid(row=3,column=2)
entryC.insert(0,info['iH'])
entryD = Entry(Window,text="Rotate",bg=bgB,fg=fgB,bd=0)
entryD.grid(row=5,column=7)
entryE = Entry(Window,text="Amount",bg=bgB,fg=fgB,bd=0)
entryE.grid(row=6,column=7)
entryF = Entry(Window,text="Password",bg=bgB,fg=fgB,bd=0,show='*')
entryF.grid(row=13,column=6)
#CheckBoxes
var=None
checkA = Checkbutton(Window,bg=bgB,fg=fgB,bd=0,activebackground=ActiveC,activeforeground=fgB,variable=var).grid(row=1,column=7,sticky='w')
checkB = Checkbutton(Window,bg=bgB,fg=fgB,bd=0,activebackground=ActiveC,activeforeground=fgB,variable=var).grid(row=2,column=7,sticky='w')
checkC = Checkbutton(Window,bg=bgB,fg=fgB,bd=0,activebackground=ActiveC,activeforeground=fgB,variable=var).grid(row=3,column=7,sticky='w')
checkD = Checkbutton(Window, text="",bg=bgB,fg=fgB,bd=0,activebackground=ActiveC,activeforeground=fgB,Avariable=var).grid(row=4,column=7,sticky='w')
#Buttons
buttonA = Button(Window,text="Confirm",bg=bgB,fg=fgB,activebackground=ActiveC,activeforeground=fgB,bd=0,command=updateButton('A')).grid(row=1,column=4)
buttonB = Button(Window,text="Confirm",bg=bgB,fg=fgB,activebackground=ActiveC,activeforeground=fgB,bd=0).grid(row=2,column=4)
buttonC = Button(Window,text="Confirm",bg=bgB,fg=fgB,activebackground=ActiveC,activeforeground=fgB,bd=0).grid(row=3,column=4)
buttonD = Button(Window,text="ACTIVATE",bg=bgB,fg=fgB,activebackground=ActiveC,activeforeground=fgB,bd=0).grid(row=5,column=9)
buttonE = Button(Window,text="ACTIVATE",bg=bgB,fg=fgB,activebackground=ActiveC,activeforeground=fgB,bd=0).grid(row=6,column=9)
buttonFIRE = Button(Window,text="Fire",bg=bgB,fg=fgB,activebackground=ActiveC,activeforeground=fgB,bd=0).grid(row=14,column=6,sticky='w')

1 Answers1

0

command= (and bind()) needs function name (callback) - it means without () and arguments

command=updateButton

If you have to use function with arguments then use lambda

command=lambda:updateButton('A')

BTW: Now your function is executed at start and its result is assigned to command= - it can be sometimes useful to generate function assigned to button.


BTW: var = Widget(...).grid(...) will assign None to variable because grid()/pack()/place() return None. You have to do in two steps

var = Widget(...)
var.grid(...)

or remove variable if you don't need it

Widget(...).grid(...)

BTW: see PEP 8 -- Style Guide for Python Code

To make code more readable we use lower_case names for variables and functions/methods - ie. window, button_a, entry_a, etc. And CamelCase names for classes.

We use space after every comma.

furas
  • 134,197
  • 12
  • 106
  • 148
  • Bravo very well explained and I am glad you brought my formatting errors to my attention. Very good answer I cannot express how much I appreciate this, so have a good day. – Apocolyptic Jan 11 '17 at 22:29