0

文件一.py

from tkinter import *
import two

root = Tk()
button = Button(text='Click me', command=two.action)
button.pack()
root.mainloop()

文件二.py

from tkinter import *
def action():

    two = Tk()

    list = [1, 2, 3]
    clicked = StringVar()
    clicked.set("Please choose PLC")
    Label(two, text="Choose PLC ", width=15, anchor='w').grid(row=0, column=0)
    drop = OptionMenu(two, clicked, *list)
    drop.config(fg='#777', width=15, height=1)
    drop.grid(row=0, column=1)

    two.mainloop()

if __name__ == '__main__':
    action()

f 我自己运行 two.py 我可以在 OptionMenu 和我选择的那个中看到一个默认值。如果我从 one.py 运行 two.py,OptionMenu 框是空的。任何想法哪里有错误?

4

0 回答 0