0
但是,它在點擊按鈕後立即在Ubuntu上發生變化。在Mac上,它會在鼠標移出根窗口時發生變化。tkinter,文本不會立即在mac osx上更改
順便說一句,msg框在Ubuntu的根窗口居中,它在Mac上的屏幕居中在預期的位置。
#coding=utf8
import Tkinter as tk
import tkMessageBox as mb
class App(object):
def __init__(self):
self.root = tk.Tk()
self.root.title('Root')
self.root.geometry("500x500")
self.frame = tk.Frame(self.root)
self.set_var()
self.content.pack()
self.button.pack()
self.frame.pack()
def set_var(self):
self.var = tk.StringVar(value="hello")
self.content = tk.Label(self.frame, textvariable=self.var)
self.button = tk.Button(self.frame, text='Show', command=self.var_change)
def var_change(self):
self.var.set("world")
mb.showinfo("Title", "Hi", parent=None)
self.var.set("hello")
def main():
app = App()
app.root.mainloop()
if __name__ == '__main__':
main()