If you press the + button, the number increases and if you press the reset button, the Python gui code is initialized, but I don't know why there is no change even if I press the button. Can't it be applied to the key?
Below is the full text of the code.
from tkinter import *
from tkinter import ttk
incr=Tk()
incr.title("increasing_numbers")
global m_num
m_num=0
#Button Commands
def click(key):
global m_num
if key=='+':
m_num+=1
else:
m_num=0
#Create result window
entry_val=StringVar(incr, value=m_num)
num_entry=ttk.Entry(incr, textvariable=entry_val, width=20)
num_entry.grid(row=0)
#+, create reset button
operator_list=['+','reset']
r=1
for btn_text in operator_list:
def cmd(x=btn_text):
click(x)
Button(incr, text=btn_text, command=cmd).grid(row=r)
r+=1
incr.mainloop()
I made you change the number to the label instead of the result window, so I succeeded! The result window was increased by writing .insert, but every time I press the button, the numbers are printed together, so I give up... I even created a - button!
from tkinter import *
from tkinter import ttk
incr=Tk()
incr.title("increasing_numbers")
global m_num
m_num=0
#Button Commands
def click(key):
global m_num
if key=='+':
m_num+=1
elif key=='-':
m_num-=1
else:
m_num=0
num_var.set(m_num)
#Create Label
num_var=IntVar()
w=Label(incr, textvariable=num_var)
w.grid(row=0)
#+,-, create reset button
operator_list=['+','-','reset']
r=1
for btn_text in operator_list:
def cmd(x=btn_text):
click(x)
ttk.Button(incr,text=btn_text,command=cmd).grid(row=r)
r+=1
incr.mainloop()
876 Uncaught (inpromise) Error on Electron: An object could not be cloned
814 M2 Mac fails to install rbenv install 3.1.3 due to errors
1269 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
782 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2025 OneMinuteCode. All rights reserved.