Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- class Example(tk.Frame):
- def __init__(self, parent, *args, **kwargs):
- super().__init__(parent, *args, **kwargs)
- self.buttons = []
- for i in range(1, 10+1):
- lab = i if i < 10 else 0
- button = tk.Button(self, text=f"{lab}",
- command=lambda x=lab: self.addtocalcs(f"{x}"))
- self.buttons.append(button)
- row = (i-1) // 3
- col = (i-1) % 3
- if row == 3: # to get row 3 button centered
- col = 1
- button.grid(row=row, column=col)
- def addtocalcs(self, value):
- print(f"addtocalcs called: {value=}")
- root = tk.Tk()
- root.resizable(False, False)
- ex = Example(root)
- ex.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement