0

出于某种原因,当从函数创建顶层窗口时,var.set(str) 不会更新 var。不过,下面的代码在放在主循环(没有函数)中时可以工作。将 mainloop 添加到函数时,它也可以按预期工作。这是预期的行为吗?

from tkinter import *
from tkinter import ttk

root = Tk()

def function():
    mainFrame = ttk.Frame(root)
    mainFrame.grid(column =1, row =1)
    configureWindow = Toplevel(mainFrame)
    pathInfoContent = StringVar()
    graphPathFrame = ttk.Frame(root)
    graphPathFrame.grid(column = 1, row =1)
    graphPathLabel = ttk.Label(graphPathFrame, text = 'GraphViz Installation Path:')
    graphPathLabel.grid(column = 1, row =1)
    graphPathLabel3 = ttk.Label(graphPathFrame, textvariable = pathInfoContent)
    graphPathLabel3.grid(column = 2, row =1)
    pathInfoContent.set('Something')  

function()

mainloop()
4

0 回答 0