Python Forum
[Tkinter] how can disable menu [About] when Toplevel is active - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] how can disable menu [About] when Toplevel is active (/thread-22036.html)



how can disable menu [About] when Toplevel is active - balenaucigasa - Oct-25-2019

Hi. I want to disable the About menu when Toplevel is active.
When the Toplevel window is closed, I want the About menu to be active again.

from tkinter import (BOTH, END, BOTTOM, DISABLED, NORMAL, 
                    Tk, Frame, Menu, Button, Label, Text, Toplevel, Message, 
                    StringVar, IntVar)
import subprocess as sub


class App(Frame):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):
        self.master.title("Centered window")
        self.pack()
        self.centerWindow()


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

        fileMenu = Menu(menubar, tearoff=0)
        fileMenu.add_command(label="ipconfig", command=self.ipconfig)
        fileMenu.add_separator()
        fileMenu.add_command(label="Exit", command=self.onExit)
        menubar.add_cascade(label="File", menu=fileMenu)

        helpMenu = Menu(menubar, tearoff=0)
        menubar.add_cascade(label="Help",  menu=helpMenu)
        helpMenu.add_command(label="About", state=NORMAL, command=self.HelpAbout)


    def centerWindow(self):
        w = 804
        h = 280

        sw = self.master.winfo_screenwidth()
        sh = self.master.winfo_screenheight()

        x = (sw - w)/2
        y = (sh - h)/2
        self.master.geometry('%dx%d+%d+%d' % (w, h, x, y))

    def HelpAbout(self):
        self.topHelp = Toplevel(self.master)
        print(str(self.topHelp.winfo_exists()))
        
        self.topHelp.title("###")
        self.MsgHelp = Message(self.topHelp)
        self.MsgHelp.pack()
        self.MsgHelp.config(text="bla bla bla")

        self.btHelp = Button(self.topHelp, text="bye", command=self.topHelp.destroy)
        self.btHelp.pack()
 
    def ipconfig(self):
      
        p = sub.Popen('ipconfig', shell=True, stdout=sub.PIPE, stderr=sub.PIPE)
        output, errors = p.communicate()
        print (output)


    def onExit(self):
        self.quit()


def main():

    root = Tk()
    root.resizable(0, 0)        #block resize window
    ex = App()
    root.mainloop()


if __name__ == '__main__':
    main()
thank you in advance for the solution