简体   繁体   English

Python Tkinter顶层不是活动窗口

[英]Python Tkinter Toplevel not the active window

I have a Python Program that opens a Toplevel window which is working I just wanted to know if there is an option to set the Toplevel window window to be active once it has been opened because at the moment it is still showing the parent window as the active window after opening it. 我有一个Python程序,可以打开正在运行的顶级窗口,我只是想知道是否存在将顶级窗口打开后将其设置为活动状态的选项,因为目前它仍将父窗口显示为打开后的活动窗口。

The python code (Python 3.4.1) python代码(Python 3.4.1)

from tkinter import *

class cl_gui:

    def __init__(self, master):

        master.title("DataBox")

        menu = Menu(master)
        master.config(menu=menu)

        menu_users = Menu(menu, tearoff=0)
        menu.add_cascade(label="Users", menu=menu_users)
        menu_users.add_command(label="View", command=self.f_openUsers)

    def f_openUsers(self):

        top = Toplevel()
        top.title("Users")

root = Tk()
app = cl_gui(root)

root.mainloop()

You can set focus onto the new Toplevel widget as follows: 您可以将焦点设置到新的“ Toplevel窗口小部件上,如下所示:

def f_openUsers(self):
    top = Toplevel()
    top.title("Users")
    top.focus_set()  # <- add this line

See eg this handy tkinter guide . 参见例如这个方便的tkinter指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM