python - "execfile" doesn't work properly -
i'm trying make launcher python program tkinter. used execfile function, , fortunately opened target gui. however, none of buttons work, , global variable functions reference isn't defined.
the code launch program:
def launch(): execfile("gui.py")
that works. base code target program:
from tkinter import * gui = tk() gui.title("this gui")
edit: example of button:
def buttonwin(): buttonwindow = toplevel(gui) button = button(buttonwindow, text = "button", width = 10, command = none) button.pack()
when references 'gui' variable toplevel, comes error. tried defining 'gui' variable in launcher script, caused target script open first, instead of launcher:
gui = tk() launcher = tk() launcher.title("launcher") def launch(): return execfile("gui.py") launchbutton = button(launcher, text = "launch", width = 10, command = launch)
when try pressing 1 of program's buttons, nameerror: $nameerror: global variable 'gui' not defined$ in python 2.7.5. thank answers, , sorry errors code blocks; i'm new.
the problem have structured tkinter program incorrectly.
in "gui.py" should have like:
from tkinter import * gui= tk() gui.mainloop()
you can add buttons perform functions , customize it:
from tkinter import * gui = tk() gui.title("this gui") def launch(): execfile("gui.py") launchbutton = button(gui, text='launch program', command=launch) launchbutton.pack() gui.mainloop()
i think function buttonwin
trying handled class; see unutbu's answer here.
i'm not sure if i've addressed problem, should start.
Comments
Post a Comment