|
1 | 1 | # User Input Window - A simple user input window program
|
2 | 2 | # Copyright (c) 2022 Ercan Ersoy
|
3 | 3 | # This file licensed under MIT License.
|
| 4 | +# Write this code using GitHub Copilot. |
4 | 5 |
|
5 |
| -import PySimpleGUI as sg |
| 6 | +import tkinter as tk |
6 | 7 |
|
7 |
| -sg.theme("SystemDefaultForReal") |
| 8 | +def on_button_click(): |
| 9 | + print(input_entry.get()) |
| 10 | + window.destroy() |
8 | 11 |
|
9 |
| -layout = [[sg.Text("Input:"), sg.In(size=(50, 1), key="INPUT"), sg.Button("OK")]] |
| 12 | +window = tk.Tk() |
| 13 | +window.title("User Input Window") |
| 14 | +window.geometry("400x100") |
10 | 15 |
|
11 |
| -window = sg.Window("User Input Window", layout, element_justification="c", |
12 |
| - size=(500, 100), finalize=True) |
| 16 | +frame = tk.Frame(window) |
| 17 | +frame.pack(anchor="center") |
13 | 18 |
|
14 |
| -while True: |
15 |
| - event, values = window.read() |
| 19 | +input_label = tk.Label(frame, text="Input") |
| 20 | +input_label.grid(row=0, column=0, sticky="w", padx=5, pady=5) |
16 | 21 |
|
17 |
| - if event == "OK": |
18 |
| - print(values["INPUT"]) |
19 |
| - break |
| 22 | +input_entry = tk.Entry(frame, width=50) |
| 23 | +input_entry.grid(row=1, column=0, padx=5, pady=5) |
20 | 24 |
|
21 |
| - if event == sg.WIN_CLOSED: |
22 |
| - break |
| 25 | +ok_button = tk.Button(frame, text="OK", command=on_button_click) |
| 26 | +ok_button.grid(row=1, column=1, sticky="e", padx=5, pady=5) |
23 | 27 |
|
24 |
| -window.close() |
| 28 | +window.mainloop() |
0 commit comments