+ 7

need help with tkinter

I need to make a program in which pressing the "+" button adds 1 to the number shown on the screen. And since I'm new to graphical interfaces, I don't know how to do it. I leave what I did so far: from tkinter import * def sumar(): resultado.set(+1) root=Tk() root.title("Contador") resultado=IntVar() Label(root,text="Contador:").grid(row=0,column=0) Entry(root,justify=CENTER,state="disable",textvariable=resultado).grid(row=0,column=1) Button(root,text="+",command=sumar).grid(row=0,column=2) root.mainloop()

7th May 2021, 8:31 PM
Yami Francø
Yami Francø - avatar
5 Respuestas
+ 10
I don't know if you mean something like this: import tkinter as tk class VentanaBoton(): def __init__(self): self.root = tk.Tk() self.text = tk.IntVar() self.text.set("1") self.label = tk.Label(self.root, textvariable=self.text) self.button = tk.Button(self.root,text="+",command=lambda: self.sumar()) self.button.pack() self.label.pack() self.root.mainloop() def sumar(self): self.text.set(self.text.get()+1) app=VentanaBoton()
7th May 2021, 9:26 PM
André Peralta Maya
André Peralta Maya - avatar
+ 2
from tkinter import * def sumar(label): text = label["text"] text = text.replace("Contador:", "") try: text = int(text) except: text = 0 text = "Contador:" + str(text + 1) label.configure(text=text) root=Tk() root.title("Contador") resultado=IntVar() label = Label(root,text="Contador:").grid(row=0,column=0) Entry(root,justify=CENTER,state="disable",textvariable=resultado).grid(row=0,column=1) Button(root,text="+",command=sumar).grid(row=0,column=2) root.mainloop()
8th May 2021, 3:49 AM
Rinaldo Nikilson
Rinaldo Nikilson - avatar
+ 2
from tkinter import * num = 0 def sumar(): global num num += 1 resultado.set(num) root=Tk() root.title("Contador") resultado=IntVar() Label(root,text="Contador:").grid(row=0,column=0) Entry(root,justify=CENTER,state="disable",textvariable=resultado).grid(row=0,column=1) Button(root,text="+",command=sumar).grid(row=0,column=2) root.mainloop()
8th May 2021, 9:39 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
+ 2
Martin Mejia don't post irrelevant answers to the post's
9th May 2021, 4:06 AM
Charan Leo25
Charan Leo25 - avatar
0
i like pony
9th May 2021, 6:40 PM
ShrekFromYourNightmares
ShrekFromYourNightmares - avatar