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

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0

    Unhappy Tkinter Label help!


    Hello,
    I need help with labels. By that I mean too many labels are showing up when I hit a button, IE if I hit Play Game I want it to display about to play game 1 time but instead it will display it twice.

    Code:
    Code:
    from Tkinter import *
    rank = 0
    root = Tk()
    root.geometry("1500x1000")
    root.title("Math Game Set 1 **RI**")
    var = StringVar()
    label = Label(root, textvariable=var, relief=RAISED)
    var.set ("Welcome to the Math Game Set 1!")
    label.pack()
    def callback():
        label = Label(root, textvariable=var, relief=RAISED)
        var.set ("Thankyou, Lets head to the Start Menu!")
        label.pack()
        
    
        
    def callback2():
        
            label = Label(root, textvariable=var, relief=RAISED)
            var.set ("START MENU")
            label.pack()
            def callback3():
                        label = Label(root, textvariable=var, relief=RAISED)
                        var.set ("About The Game, The game that you are running is about learning math and much much more.")
    
                        
            def callback4():
                        label = Label(root, textvariable=var, relief=RAISED)
                        var.set ("Ranking: " + str (rank))
                        label.pack()
    
            def callback5():
                        label = Label(root, textvariable=var, relief=RAISED)
                        var.set ("You are about to start the game!")
                        label.pack()
                        import time
                        time.sleep(1)
    
            
            b = Button(root, text="Play Game", command=callback5)
            b.pack()
            b = Button(root, text="Ranks", command=callback4)
            b.pack()           
            b = Button(root, text="About the Game", command=callback3)
            b.pack()
           
    
    b = Button(root, text="To the menu", command=callback2)
    b.pack()
        
    
    
    
    var = IntVar()
    
    
    
    
    def onclick():
       pass
    
    text = Text(root)
    
    text.pack()
    
    text.tag_add("here", "1.0", "1.4")
    text.tag_add("start", "1.8", "1.13")
    root.mainloop()
    def donothing():
       filewin = Toplevel(root)
       button = Button(filewin, text="Do nothing button")
       button.pack()
    
    if text1 == '2':
        print ('Good Work')
    
    menubar = Menu(root)
    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="New", command=donothing)
    filemenu.add_command(label="Open", command=donothing)
    filemenu.add_command(label="Save", command=donothing)
    filemenu.add_command(label="Save as...", command=donothing)
    filemenu.add_command(label="Close", command=donothing)
    
    filemenu.add_separator()
    
    filemenu.add_command(label="Exit", command=donothing)
    menubar.add_cascade(label="File", menu=filemenu)
    editmenu = Menu(menubar, tearoff=0)
    editmenu.add_command(label="Undo", command=donothing)
    
    editmenu.add_separator()
    
    editmenu.add_command(label="Cut", command=donothing)
    editmenu.add_command(label="Copy", command=donothing)
    editmenu.add_command(label="Paste", command=donothing)
    editmenu.add_command(label="Delete", command=donothing)
    editmenu.add_command(label="Select All", command=donothing)
    
    menubar.add_cascade(label="Edit", menu=editmenu)
    helpmenu = Menu(menubar, tearoff=0)
    helpmenu.add_command(label="Help Index", command=donothing)
    helpmenu.add_command(label="About...", command=donothing)
    menubar.add_cascade(label="Help", menu=helpmenu)
    
    
    root.mainloop()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Let's simplify your program. When run in python2 (Tkinter, not tkinter) the code makes a tiny window with a button. Every time you click the button callback2 makes and packs a new label.
    Code:
    from Tkinter import *
    
    def callback2():
        label = Label(root, text="START MENU", relief=RAISED)
        label.pack()
    
    root = Tk()
    b = Button(root, text="To the menu", command=callback2)
    b.pack()
    root.mainloop()
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo