Created
May 9, 2023 10:31
-
-
Save etherealxx/62dda713852a55ac0951a285babbf107 to your computer and use it in GitHub Desktop.
Tally to compare 2 values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tkinter compare | |
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