[英]How do I get tkinter label text to update without waiting for the tkinter Menu command function to finish?
[英]How do I reassign Label text with Tkinter from a different function
from tkinter import *
# reassigns variables for label and button texts
def Ctrack(vname, vvalue):
#global vname
vname = vvalue
#place holder to check which button has been clicked
print(vname)
#labeltext = reassign label text bas
# creates labels and buttons
def buttons():
root = Tk()
#first label
winlabel = Label(root, text =labeltext )
winlabel.grid(row = 0, column = 1, padx = 10, pady = 10)
#first button
but1 = Button(root, text = "button 1", command = lambda *args: Ctrack(0, 1))
but1.grid(row = 0, column = 2, padx = 10, pady = 10)
#second button
but2 = Button(root, text = "button 2", command = lambda *args: Ctrack(0, 2))
but2.grid(row = 0, column = 3, padx = 10, pady = 10)
root.mainloop()
buttons()
(第一次使用 Stackoverflow)
如何將按鈕函數中的標簽文本重新分配給我在 Ctrack 函數中分配的變量?
您可以讓 Ctrack() 函數能夠在根窗口上發布標簽。 如果您采用這種方法,您可以在 Ctrack() 中添加“root”作為參數,然后在 Ctrack() 函數中聲明並打包標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.