0

So I'm writing this game in python with Tkinter. The game works by calling a function that changes the values of the text variables, and button variables. When the button is pushed that calls the function however, the screen does not redraw and call up the new variables and just displays the old text.

startGame()

win=Tkinter.Tk()
win.title("TREASURE QUEST!!")
Textlabel=Tkinter.Label\
  (win,text = text1,font=('Times New Roman',12),wraplength=600,)
Textlabel.pack()
Row2=Tkinter.Frame(win)
Btn1=Tkinter.Button\
  (Row2, text=button1Name, command= button1(),font=('Times New Roman',12))
Btn2=Tkinter.Button\
  (Row2, text=button2Name, command= button2(), font=('Times New Roman',12))
Btn1.pack(side='left')
Btn2.pack(side='left')
Row2.pack()

win.mainloop()



def startGame():
    global text1,button1,button1Name,button2,button2Name
    ##adds name
    ##button that calls StoryCard

    text1="Welcome to Treasure Quest!! The Game that allows you to pick your own destiny! Treasure quest is a very simple game. The story will display on the screen until it reaches an event. At each event you will be shown two choices. Each decision may cause you to leave with more treasure or to die a horrible death... Still like any true or false question on a final exam, you only have a 50/50 chance of ruining your entire life if you do not know! Now that you know how to play, please click the button below to start the game!" 
    button1=introCard
    button1Name="Play"

    button2=kill
    button2Name="Quit"
Kevin
  • 72,202
  • 12
  • 116
  • 152
Logan Henry
  • 63
  • 1
  • 10
  • It'd be useful to know what `button1()` and `button2()` do exactly (just show the code of them, too). – TidB Oct 24 '14 at 19:24
  • 1
    You are *calling* the functions, and assigning their *return values* to the buttons. Remove the parentheses! – jonrsharpe Oct 24 '14 at 19:25
  • possible duplicate of [Why is tkinter-Button parameter "command" executed when declared?](http://stackoverflow.com/questions/8269096/why-is-tkinter-button-parameter-command-executed-when-declared) – jonrsharpe Oct 24 '14 at 19:25
  • I did! button1 and button2 are the variables I'm referring to. In the function startGame it calls them (the names they are set to above are the titles of another function. As weird a layout as this one is it does seem to work. – Logan Henry Oct 24 '14 at 19:28
  • @jonrsharpe Thanks! that did fix my buttons I set a print statement in the function I was calling so I could see if it went and it did. The buttons still redefine when the variable changes though. – Logan Henry Oct 24 '14 at 19:31
  • 2
    Generally, you change the text of a button with `mybutton.config(text="whatever")`, not by redefining the string that it points to. – Kevin Oct 24 '14 at 19:39

0 Answers0