Advertisement
Mangaread32

tally counter

Mar 14th, 2023 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | Source Code | 0 0
  1. import tkinter as tk
  2.  
  3. class TallyCounter:
  4.     def __init__(self, master):
  5.         self.master = master
  6.         master.title("Tally Counter")
  7.        
  8.         self.count = 0
  9.  
  10.         self.label = tk.Label(master, text="Count: " + self.get_tally())
  11.         self.label.config(fg="white")
  12.         self.label.pack()
  13.         self.label.pack(pady=10)
  14.         self.plus_button = tk.Button(master, text="+", command=self.increment)
  15.         self.plus_button.pack(side=tk.LEFT)
  16.  
  17.         self.minus_button = tk.Button(master, text="-", command=self.decrement)
  18.         self.minus_button.pack(side=tk.LEFT)
  19.        
  20.         self.plus_5_button = tk.Button(master, text="+5", command=self.increment_by_5)
  21.         self.plus_5_button.pack(side=tk.LEFT)
  22.  
  23.         self.minus_5_button = tk.Button(master, text="-5", command=self.decrement_by_5)
  24.         self.minus_5_button.pack(side=tk.LEFT)
  25.        
  26.         self.custom_plus_button = tk.Button(master, text="Custom +", command=self.custom_increment)
  27.         self.custom_plus_button.pack(side=tk.LEFT)
  28.  
  29.         self.custom_minus_button = tk.Button(master, text="Custom -", command=self.custom_decrement)
  30.         self.custom_minus_button.pack(side=tk.LEFT)
  31.        
  32.         self.custom_plus_entry = tk.Entry(master)
  33.         self.custom_plus_entry.pack(side=tk.LEFT)
  34.        
  35.         self.custom_minus_entry = tk.Entry(master)
  36.         self.custom_minus_entry.pack(side=tk.LEFT)
  37.  
  38.     def increment(self):
  39.         self.count += 1
  40.         self.update_label()
  41.  
  42.     def decrement(self):
  43.         if self.count > 0:
  44.             self.count -= 1
  45.             self.update_label()
  46.            
  47.     def increment_by_5(self):
  48.         self.count += 5
  49.         self.update_label()
  50.  
  51.     def decrement_by_5(self):
  52.         if self.count >= 5:
  53.             self.count -= 5
  54.             self.update_label()
  55.  
  56.     def custom_increment(self):
  57.         increment_val = int(self.custom_plus_entry.get())
  58.         self.count += increment_val
  59.         self.update_label()
  60.  
  61.     def custom_decrement(self):
  62.         decrement_val = int(self.custom_minus_entry.get())
  63.         if self.count >= decrement_val:
  64.             self.count -= decrement_val
  65.             self.update_label()
  66.  
  67.     def get_tally(self):
  68.         x_count = self.count // 5
  69.         pipe_count = self.count % 5
  70.         m_count = x_count // 10
  71.         remaining_x_count = x_count % 10
  72.         if m_count > 0:
  73.             return "E " * m_count + self.get_remaining_tally(remaining_x_count, pipe_count)
  74.         else:
  75.             return self.get_remaining_tally(remaining_x_count, pipe_count)
  76.  
  77.     def get_remaining_tally(self, x_count, pipe_count):
  78.         if x_count == 2:
  79.             return "M" + "| " * (pipe_count - 1)
  80.         elif x_count > 2:
  81.             return "M " * (x_count // 2) + "M" * (x_count % 2) + "| " * pipe_count
  82.         elif pipe_count == 0:
  83.             return "X " * x_count
  84.         else:
  85.             return "X " * x_count + "| " * pipe_count
  86.  
  87.     def update_label(self):
  88.         self.label.config(text="Count: " + self.get_tally())
  89.  
  90. root = tk.Tk()
  91. counter = TallyCounter(root)
  92. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement