0

File one.py

from tkinter import *
import two

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

File two.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 I run two.py by itself I can see a default value at OptionMenu and the one I chose as well. If I ran two.py from one.py the OptionMenu box is empty. Any ideas where is an error?

Kirill Ivanov
  • 77
  • 1
  • 8
  • 3
    This is probably caused by having multiple instances of Tk. There can only be one instance of Tk in a program. I would recommend changing `two = Tk()` to `two = Toplevel()`. Toplevel windows work the same as Tk windows, but don't cause problems. – Henry Sep 19 '21 at 13:05
  • Thanks Henry, I knew that would be some sintax issue. Thats solved the problem. – Kirill Ivanov Sep 20 '21 at 06:02

0 Answers0