Hey look, the AI wrote a phone keypad for me in literally one minute.
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
|
||||||
|
class DialPad(tk.Tk):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
# Set up the main window
|
||||||
|
self.title("Phone Dial Pad")
|
||||||
|
self.geometry("400x500")
|
||||||
|
|
||||||
|
# Create the text field to display the dialed number
|
||||||
|
self.number_var = tk.StringVar()
|
||||||
|
self.number_entry = tk.Entry(self, textvariable=self.number_var, font=("Helvetica", 16), justify="right")
|
||||||
|
self.number_entry.grid(row=0, column=0, columnspan=3, padx=10, pady=10, ipadx=10, ipady=10)
|
||||||
|
|
||||||
|
# Create the dial pad buttons
|
||||||
|
pad_buttons = [
|
||||||
|
("1", 1, 0), ("2", 1, 1), ("3", 1, 2),
|
||||||
|
("4", 2, 0), ("5", 2, 1), ("6", 2, 2),
|
||||||
|
("7", 3, 0), ("8", 3, 1), ("9", 3, 2),
|
||||||
|
("*", 4, 0), ("0", 4, 1), ("#", 4, 2),
|
||||||
|
]
|
||||||
|
|
||||||
|
for button_text, row, column in pad_buttons:
|
||||||
|
button = tk.Button(self, text=button_text, font=("Helvetica", 16), command=lambda text=button_text: self.add_digit(text))
|
||||||
|
button.grid(row=row, column=column, padx=10, pady=10, ipadx=20, ipady=20)
|
||||||
|
|
||||||
|
# Create the clear button
|
||||||
|
clear_button = tk.Button(self, text="Clear", font=("Helvetica", 16), command=self.clear_number)
|
||||||
|
clear_button.grid(row=5, column=0, columnspan=3, padx=10, pady=10, ipadx=100, ipady=10)
|
||||||
|
|
||||||
|
def add_digit(self, digit):
|
||||||
|
current_number = self.number_var.get()
|
||||||
|
self.number_var.set(current_number + digit)
|
||||||
|
|
||||||
|
def clear_number(self):
|
||||||
|
self.number_var.set("")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = DialPad()
|
||||||
|
app.mainloop()
|
||||||
Reference in New Issue
Block a user