Advertisement
Guest User

Untitled

a guest
Jun 25th, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. class Example(tk.Frame):
  4. def __init__(self, parent, *args, **kwargs):
  5. super().__init__(parent, *args, **kwargs)
  6.  
  7. self.buttons = []
  8. for i in range(1, 10+1):
  9. lab = i if i < 10 else 0
  10. button = tk.Button(self, text=f"{lab}",
  11. command=lambda x=lab: self.addtocalcs(f"{x}"))
  12. self.buttons.append(button)
  13.  
  14. row = (i-1) // 3
  15. col = (i-1) % 3
  16. if row == 3: # to get row 3 button centered
  17. col = 1
  18. button.grid(row=row, column=col)
  19.  
  20. def addtocalcs(self, value):
  21. print(f"addtocalcs called: {value=}")
  22.  
  23.  
  24. root = tk.Tk()
  25. root.resizable(False, False)
  26. ex = Example(root)
  27. ex.pack()
  28. root.mainloop()
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement