Skip to content

Instantly share code, notes, and snippets.

@etherealxx
Created April 19, 2023 13:28
Show Gist options
  • Save etherealxx/f3eb913a4e57b2f8b0de4f51a67f913a to your computer and use it in GitHub Desktop.
Save etherealxx/f3eb913a4e57b2f8b0de4f51a67f913a to your computer and use it in GitHub Desktop.
A tally to compare two variable, made with Tkinter
#github.com/etherealxx
import tkinter as tk
class App(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
# create the first textbox and buttons
self.textbox1 = tk.Text(self, height=1, width=10)
self.textbox1.grid(row=0, column=0, padx=5, pady=5)
self.plus1 = tk.Button(self, text="+", command=self.increment1)
self.plus1.grid(row=0, column=2, padx=5, pady=5)
self.minus1 = tk.Button(self, text="-", command=self.decrement1)
self.minus1.grid(row=0, column=3, padx=5, pady=5)
# create the second textbox and buttons
self.textbox2 = tk.Text(self, height=1, width=10)
self.textbox2.grid(row=1, column=0, padx=5, pady=5)
self.plus2 = tk.Button(self, text="+", command=self.increment2)
self.plus2.grid(row=1, column=2, padx=5, pady=5)
self.minus2 = tk.Button(self, text="-", command=self.decrement2)
self.minus2.grid(row=1, column=3, padx=5, pady=5)
# create the labels for the counters
self.counter1 = tk.Label(self, text="0")
self.counter1.grid(row=0, column=1, padx=5, pady=5)
self.counter2 = tk.Label(self, text="0")
self.counter2.grid(row=1, column=1, padx=5, pady=5)
def increment1(self):
self.counter1.config(text=str(int(self.counter1["text"]) + 1))
def decrement1(self):
self.counter1.config(text=str(int(self.counter1["text"]) - 1))
def increment2(self):
self.counter2.config(text=str(int(self.counter2["text"]) + 1))
def decrement2(self):
self.counter2.config(text=str(int(self.counter2["text"]) - 1))
root = tk.Tk()
app = App(master=root)
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment