如何在单击子窗口时打开菜单按钮禁用菜单按钮,直到子窗口在 tkinter 中关闭

如何解决如何在单击子窗口时打开菜单按钮禁用菜单按钮,直到子窗口在 tkinter 中关闭

我在父窗口上创建了一个菜单栏。我制作了一个子窗口作为 userguide.py,它被分配给菜单上的“用户指南”按钮之一。当我单击该按钮时,子窗口会打开,但再次单击时,它会打开另一个窗口,如果单击菜单按钮,则会继续。如何在子窗口关闭之前禁用菜单按钮。我正在分享下面的代码

下面是父窗口菜单代码

from tkinter import *
from tkinter import ttk
from userguide import userGuide 

root = Tk()
root.title("GhostTube - by rusher")
root.iconbitmap(r"C:\Users\ayush\Desktop\BOTRAW\main\ghost.ico")
root.maxsize(400,685)
root.minsize(400,685)
root.geometry("400x685")

style = ttk.Style()
style.theme_use("clam")
menubar = Menu(root) 
menubar.add_command(label="USER GUIDE    I",command=userGuide)
menubar.add_command(label="ABOUT    I")
menubar.add_command(label="CONTACT",command=contactInfo)

root.config(menu=menubar)
root.mainloop()`

Menu bar image

下面给出的代码是子窗口代码,即userguide.py

from tkinter import *
from tkinter import ttk

def userGuide():

    master = Tk()
    master.title("GhostTube - by rusher")
    master.iconbitmap(r"C:\Users\ayush\Desktop\BOTRAW\main\ghost.ico")
    master.maxsize(400,685)
    master.minsize(400,685)
    master.geometry("400x685")

    style = ttk.Style()
    style.theme_use("clam")


    userLabel = Label(master,text="                  HOW TO USE                  ",bg="black",fg="white",font=("Elephant",18))
    userLabel.grid(pady=10)

    guide1Frame = LabelFrame(master,text="STEP 1 :",padx=5,pady=10)
    guide1Frame.grid(row=1,column=0,padx=5)

    step1label = Label(guide1Frame,text="First step is to add accounts to the bot,for that click on \n“Load Accounts” then locate the “YT accounts.txt” file and select it.\nIt will load all the accounts in the file.")
    step1label.grid()

    guide2Frame = LabelFrame(master,text="STEP 2 :",pady=10)
    guide2Frame.grid(row=2,padx=5)

    step2label = Label(guide2Frame,text="Add the video URL of which you want to boost. Type or copy paste \nyour video URL on (Type Here) space and click on “Add”. \nor you can make a text file of your video URLs and load it \nby clicking on “Load Video URLs” and selecting the text file.")
    step2label.grid()

    guide3Frame = LabelFrame(master,text="STEP 3 :",pady=10)
    guide3Frame.grid(row=3,padx=5)

    step3label = Label(guide3Frame,text="Now you need to select the action you want to have \non the video to be performed,that are: LIKE,disLIKE,\nSUBSCRIBE,UNSUBSCRIBE or COMMENT. You can select multiple \nactions at a time. After completing this Click on “START” button.")
    step3label.grid()

    guide4Frame = LabelFrame(master,text="STEP 4 :",pady=10)
    guide4Frame.grid(row=4,padx=5)

    step4label = Label(guide4Frame,text="For Comments,You can Type or copy paste comments on\n(Type Here) of your choice,one comment at a time then click\non “Add” button and then type next comment of your choice then\nclick on “Add” and repeat if you want more. Or you can make\na text file of comments of your choice (one comment per line)\nand load it by clicking on “Load Comments”and locate your\ncomments text file and select it. Then click on “START”.")
    step4label.grid()

    guide5Frame = LabelFrame(master,text="STEP 5 :",pady=10)
    guide5Frame.grid(row=5,padx=5)

    step5label = Label(guide5Frame,text="When the bot runs first time it can take time because of it prepares\nthe system,after the process starts please do not intercept it.\nLet it complete all the actions. The process goes in steps; \nfirst,a CMD interface will open then a Firefox window will start and\nit will complete one action then the Firefox window will close and\nthe same steps will repeat according to the actions to be taken.")
    step5label.grid()

    quote = Frame(master,pady=10)
    quote.grid(row=6,columnspan=2)

    enjoy = Label(quote,text="Experience The Best",16),fg="white")
    enjoy.grid(padx=5)

    master.mainloop()

请帮帮我,因为我是这个话题的新手。

解决方法

尝试这样的事情:

import tkinter as tk

def create_window(root):
    # Create the new window
    top = tk.Toplevel(root)
    # Stop the user from interacting with the main window
    top.grab_set()

root = tk.Tk()

menubar = tk.Menu(root) 
menubar.add_command(label="Create new window",command=lambda: create_window(root))
root.config(menu=menubar)

root.mainloop()

它使用 top.grab_set() 来阻止用户与主窗口交互。它会阻止所有事件,直到用户关闭弹出窗口。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?