Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- class TallyCounter:
- def __init__(self, master):
- self.master = master
- master.title("Tally Counter")
- self.count = 0
- self.label = tk.Label(master, text="Count: " + self.get_tally())
- self.label.config(fg="white")
- self.label.pack()
- self.label.pack(pady=10)
- self.plus_button = tk.Button(master, text="+", command=self.increment)
- self.plus_button.pack(side=tk.LEFT)
- self.minus_button = tk.Button(master, text="-", command=self.decrement)
- self.minus_button.pack(side=tk.LEFT)
- self.plus_5_button = tk.Button(master, text="+5", command=self.increment_by_5)
- self.plus_5_button.pack(side=tk.LEFT)
- self.minus_5_button = tk.Button(master, text="-5", command=self.decrement_by_5)
- self.minus_5_button.pack(side=tk.LEFT)
- self.custom_plus_button = tk.Button(master, text="Custom +", command=self.custom_increment)
- self.custom_plus_button.pack(side=tk.LEFT)
- self.custom_minus_button = tk.Button(master, text="Custom -", command=self.custom_decrement)
- self.custom_minus_button.pack(side=tk.LEFT)
- self.custom_plus_entry = tk.Entry(master)
- self.custom_plus_entry.pack(side=tk.LEFT)
- self.custom_minus_entry = tk.Entry(master)
- self.custom_minus_entry.pack(side=tk.LEFT)
- def increment(self):
- self.count += 1
- self.update_label()
- def decrement(self):
- if self.count > 0:
- self.count -= 1
- self.update_label()
- def increment_by_5(self):
- self.count += 5
- self.update_label()
- def decrement_by_5(self):
- if self.count >= 5:
- self.count -= 5
- self.update_label()
- def custom_increment(self):
- increment_val = int(self.custom_plus_entry.get())
- self.count += increment_val
- self.update_label()
- def custom_decrement(self):
- decrement_val = int(self.custom_minus_entry.get())
- if self.count >= decrement_val:
- self.count -= decrement_val
- self.update_label()
- def get_tally(self):
- x_count = self.count // 5
- pipe_count = self.count % 5
- m_count = x_count // 10
- remaining_x_count = x_count % 10
- if m_count > 0:
- return "E " * m_count + self.get_remaining_tally(remaining_x_count, pipe_count)
- else:
- return self.get_remaining_tally(remaining_x_count, pipe_count)
- def get_remaining_tally(self, x_count, pipe_count):
- if x_count == 2:
- return "M" + "| " * (pipe_count - 1)
- elif x_count > 2:
- return "M " * (x_count // 2) + "M" * (x_count % 2) + "| " * pipe_count
- elif pipe_count == 0:
- return "X " * x_count
- else:
- return "X " * x_count + "| " * pipe_count
- def update_label(self):
- self.label.config(text="Count: " + self.get_tally())
- root = tk.Tk()
- counter = TallyCounter(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement