python - Make a Tkinter Toplevel active -
i trying make toplevel
widget active window on screen (i want if press enter, exits window. have key bound widget, can't seem window main window on computer. running program using notepad++ (i have shortcut specific program since using lot).
here code:
def main(): root = tk(classname = ' module opener') app = getfilename(root) root.rowconfigure(0, weight = 1) root.columnconfigure(0, weight = 1) root.bind('<return>', (lambda e, b=app.gobutton: b.invoke())) root.mainloop() f, pythontype = app.filename, app.pythontype if f[-3:] != '.py': f += '.py' modulefile = getfilepath(f, pythontype) if not modulefile none: subprocess.call([r"c:\program files\notepad++\notepad++.exe", modulefile]) else: root.withdraw() finalroot = toplevel(root) finalroot.grab_set() # thought make active finalapp = filenotexist(finalroot, f) finalroot.rowconfigure(0, weight = 1) finalroot.columnconfigure(0, weight = 1) finalroot.bind('<return>', (lambda e, b=finalapp.okbutton: b.invoke())) finalroot.mainloop()
i want when opens, if press enter, command; however, have click in window first becomes active, , works.
i tried various things such finalroot.lift()
, finalroot.focus_set()
, finalroot.grab_set()
/finalroot.grab_set_global()
(i saw these methods another question), , finalroot.focus()
.
the first window tk()
active when program starts. however, toplevel()
not. tried making 2 tk()
's (destroying root
, creating finalroot
new tk()
instance), did not work well. how can this? thanks!
...however, have click in window first becomes active, , works.
i encountered problem , while researching solution, found thread. i'm using windows 7 professional. did call both grab_set()
, focus()
, solved problem me. have finalroot.grab_set()
, add:
finalroot.focus()
it worked in case.
Comments
Post a Comment