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()
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
581 PHP ssh2_scp_send fails to send files as intended
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.