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

    Join Date
    Oct 2017
    Rep Power

    [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:
    # 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
        # Create the init_window
        def init_window(self):
            # Changing the Title of my first page
            # The Widget
            self.pack(fill=BOTH, expand=1)
            # Create an Menu
            menu = Menu(self.master)
            # 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 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
                # Define the init_soundplay
                def init_soundplay(self):
                    # Change the Title of My Seccond Page
                    # Set it as Pack
                    self.pack(fill=BOTH, expand=1)
                    # Make Button
                    self.master.butExit = Button(self, text="WinExit", command=self.__playSystemExit)
                # Define the playSystem button in Working
                def __playSystemExit(self):
                    winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
            # Make App-Page2 (My seccond page)
            root1 = Tk()
            app1 = WinSound(root1)
        # Define the Exit
        def client_exit(self):
    # Make App-Page Defeult... my first page
    rootMain = Tk()
    appMain = Window(rootMain)

    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
    Rep Power
    This program creates two windows, each with an operational button.
    import tkinter
    def g():
    def f():
        r = tkinter.Toplevel()
        tkinter.Button(r, text='SNEEZE', command=g).pack()
    tkinter.Button(text='HELLO', command=f).pack()
    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 09:17 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo