python 3.x - tkinter sequential execution ordering -


i having trouble code won't execute code @ point. can't describe problem in wording, in code, remaining code under window.mainloop() not run need unless main window (gui) closed problematic. want able print(t.test) when code under def calculate has been executed. technically removing window.mainloop() run code before can gather input vital. need keep structure of coding same shown below well.

import tkinter  class test:    def __init__(self):     self.test = false  def calculate(window, userinput, t):   test = userinput.get()   print(test)   window.destroy()   t.test = true  def main():    t = test()   gui = tkinter.tk()   gui.title("example window")   gui.geometry("400x400")    userinput = tkinter.stringvar()    window = tkinter.toplevel()   window.title("entry")   tkinter.message(window, text="label", width="200").pack()   tkinter.entry(window, width=30, textvariable=userinput).pack()   tkinter.button(window, text="ok", command=lambda: calculate(window, userinput, t)).pack()   window.mainloop()    print(t.test)    gui.mainloop()  main() 

edit: seems able make behave same way , keep same structure putting print(t.test) under own defined function , calling under def calculate(userinput, window, t) in last line. tested causes main window freeze.

the way tkinter designed work you:

  1. create widgets
  2. call mainloop (exactly once)
  3. the window destroyed , program exits

you shouldn't call mainloop more once, , shouldn't have more code after call mainloop.

if want run after call mainloop, schedule after:

... gui.after(1, do_something) gui.mainloop() 

anything scheduled after run after mainloop has started.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -