So I have the code here:
import tkinter as tk
def add_x(x,y):
return y + x
class creator():
def __init__(self,val):
self.val = val
self.root = tk.Tk()
def func(self,cmd,amount):
change_val = cmd(self.val,amount)
self.val = change_val
return self.val
def btn(self,cmd):
btn_text = tk.StringVar()
def update_btn_text(var):
btn_text.set(var)
btn = tk.Button(self.root, textvariable=btn_text,
command = update_btn_text(cmd))
btn_text.set(0)
btn.pack()
def run(self):
self.root.mainloop()
a = creator(0)
a.btn(a.func(add_x,1))
What this is supposed to do is create a button that will increase the displayed text by one each time it is pressed. The issue is that when I try running it, nothing will happen and it will only change a.val to 1 at the beginning and keep the button text at 0. Does anyone know why this is happening? Thanks! This got closed because it was associated with another question, but nothing there answered my question. Using lambda breaks my code and partial does nothing.