-3

So i have this program that when i press an button it says something. then when i press another button it changes the first buttons outcome. but the outcome dont want to get "updated".

import sys
from Tkinter import *
mGui = Tk()
Answer = "NO"

def Truth():
        Answer.replace("NO","YES")
        print(Answer)

def Snonk():
        print(Answer)

canvas = Canvas(mGui, width=200, height=300, bg="white")
mbutton = Button(mGui,text ="Is Hugo cool?",command = Snonk,).pack()
mbutton2 = Button(mGui,text ="Truth",command = Truth,).pack()
canvas.pack()
mGui.title("PQ")

mGui.mainloop()

e here

Grusen
  • 1

1 Answers1

1

You need to change the text of the button, not the variable that it's using. Use something like

my_button.config(text="My new text here")

in your functions if you want to keep them updated properly.

Here's a simpler example of what you're doing, and how to fix the problem

In [1]: a_str = ""

In [2]: a_dict = {"key" : a_str}

In [3]: a_dict
Out[3]: {'key': ''}

In [4]: a_str = "something else"

In [5]: a_dict
Out[5]: {'key': ''}

If you want to change the value of a_dict['key'], you need to reassign it, you can't just change what the variable used to be.

TankorSmash
  • 12,186
  • 6
  • 68
  • 106