How to change Tkinter label text on button press
You can make
StringVar to make callback.
message = tkinter.StringVar() message.set('Not pressed.')
You need to set
message to be a
Instruction = tkinter.Label(Tk, textvariable=message, font='size, 20').pack()
def press(): message.set('Button Pressed')
PhoenixUpdated on October 02, 2020
Phoenix over 2 years
I have this code, and its meant to change the text of the
Instructionlabel when the item button is pressed. It doesn't for some reason, and I'm not entirely sure why. I've tried creating another button in the
press()function with the same names and parameters except a different text.
import tkinter import Theme import Info Tk = tkinter.Tk() message = 'Not pressed.' #Sets window Options Tk.wm_title(Info.Title) Tk.resizable(width='FALSE', height='FALSE') Tk.wm_geometry("%dx%d%+d%+d" % (720, 480, 0, 0)) #Method run by item button def press(): message = 'Button Pressed' Tk.update() #item button item = tkinter.Button(Tk, command=press).pack() #label Instruction = tkinter.Label(Tk, text=message, bg=Theme.GUI_hl2, font='size, 20').pack() #Background Tk.configure(background=Theme.GUI_bg) Tk.mainloop()
Phoenix about 8 yearsPY_VAR0 has replaced the "Button Not Pressed" and "Button Pressed" text it would seem
fdsa about 8 years@Phoenix don't understand your comment
Phoenix about 8 yearsWhen I run my program, It displays "PY_VAR0" Instead of "Button Pressed", which should be displayed after it is pressed, or "Not Pressed" before it is pressed.
Pyd about 5 years
AttributeError: 'NoneType' object has no attribute '_root'
Critical issues have been reported with the following SDK versions: com.google.android.gms:play-services-safetynet:17.0.0