#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    22
    Rep Power
    0

    [Python 3 + Tkinter] Buttons not Showing, help needed!


    Hey Python Programmers...

    I try to create an GUI they get two or more pages... this is an training...
    I try to create working with menus and buttons in one script...

    This is my script:
    Code:
    # Import Tkinter
    from tkinter import *
    
    # Write my first page
    class Window(Frame):
    
        # Define an __init__
        def __init__(self, master=None):
            
            # Parameters: 
            Frame.__init__(self, master)   
    
            # Make Master                
            self.master = master
    
            # Window
            self.init_window()
    
        # Create the init_window
        def init_window(self):
    
            # Changing the Title of my first page
            self.master.title("GUI")
    
            # The Widget
            self.pack(fill=BOTH, expand=1)
    
            # Create an Menu
            menu = Menu(self.master)
            self.master.config(menu=menu)
    
            # Create an File Object, called File
            file = Menu(menu)
            file.add_command(label="Win Sound", command=self.client_winsound)
            file.add_command(label="Exit", command=self.client_exit)
            menu.add_cascade(label="File", menu=file)
    
            # Create an File Object, called Edit
            edit = Menu(menu)
    
            # The Command of Undo in the Edit Tab
            edit.add_command(label="Undo")
    
            # Edit Cascade
            menu.add_cascade(label="Edit", menu=edit)
    
        # Define the WinSound Window
        def client_winsound(self):
    
            # Make the WinSound Window
            class WinSound(Frame):
    
                # Define the WinSound Init
                def __init_winsound(self, master=None):
    
                    # Called by Frame
                    Frame.__init__winsound(self, master)
    
                    # Create it as Master
                    self.master = master
    
                    # Called by init_soundplay
                    self.init__soundplay()
    
                # Define the init_soundplay
                def init_soundplay(self):
    
                    # Change the Title of My Seccond Page
                    self.master.title("WinSound")
    
                    # Set it as Pack
                    self.pack(fill=BOTH, expand=1)
    
                    # Make Button
                    self.master.butExit = Button(self, text="WinExit", command=self.__playSystemExit)
                    self.master.butExit.pack()
    
                # Define the playSystem button in Working
                def __playSystemExit(self):
                    winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
    
            # Make App-Page2 (My seccond page)
            root1 = Tk()
            root1.geometry("400x300")
            app1 = WinSound(root1)
            root1.mainloop()
                     
        # Define the Exit
        def client_exit(self):
            exit()
    
            
    # Make App-Page Defeult... my first page
    rootMain = Tk()
    rootMain.geometry("640x480")
    appMain = Window(rootMain)
    rootMain.mainloop()

    This is my script... i try to create an app with python and tkinter... This App must be get an
    two or more pages... one with an menu, an the seccond page with buttons for play diffrence
    WinSounds, this is only an training to get knowledge with python tkinter.... i try to learn this...

    But my problem is, thad if you start my seccond page, the play sound button(s) are not showed...
    Can anyone correct my code, just it works and the buttons are showed - even they are
    working.... If you don't know what my problem is... copy, past and run my script... test my
    App and you can see what the problem is... the problem sit in my "WinSound" button in the
    File Menu Part in my first page...

    This is an test only... not an real app... only i try to learn tkinter.... just i get help needed...

    Python Version: Python v3.... Tkinter + WinSound Module...

    Can anyone helpme ?...
    Thanks, Jamie.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,915
    Rep Power
    509
    This program creates two windows, each with an operational button.
    Code:
    import tkinter
    
    def g():
        print('GESUNDHEIT')
    
    def f():
        r = tkinter.Toplevel()
        tkinter.Button(r, text='SNEEZE', command=g).pack()
        r.mainloop()    
    
    tkinter.Button(text='HELLO', command=f).pack()
    tkinter.mainloop()
    
    help(tkinter.Toplevel)
    Do you have a good reason to nest class WinSound(Frame): within another method?

    I put print statements into def __init_winsound(self, master=None): and
    def init_soundplay(self):
    neither print statement is called. Your program does not call these functions. Perhaps you also need to pack the WinSound object, app1.

    Is there a spelling error between
    __init_winsound and
    __init__winsound ?
    Last edited by b49P23TIvg; December 10th, 2017 at 10:17 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo