Created
July 27, 2024 16:47
-
-
Save CoreyMSchafer/558014ea68297f4fc89f46513260bb00 to your computer and use it in GitHub Desktop.
Python Tkinter Tutorial - Part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
from tkinter import ttk | |
root = tk.Tk() | |
root.title("Simple App") | |
def add_to_list(event=None): | |
text = entry.get() | |
if text: | |
text_list.insert(tk.END, text) | |
entry.delete(0, tk.END) | |
root.columnconfigure(0, weight=1) | |
root.columnconfigure(1, weight=3) | |
root.rowconfigure(0, weight=1) | |
frame = ttk.Frame(root) | |
frame.grid(row=0, column=0, sticky="nsew", padx=5, pady=5) | |
frame.columnconfigure(0, weight=1) | |
frame.rowconfigure(1, weight=1) | |
entry = ttk.Entry(frame) | |
entry.grid(row=0, column=0, sticky="ew") | |
entry.bind("<Return>", add_to_list) | |
entry_btn = ttk.Button(frame, text="Add", command=add_to_list) | |
entry_btn.grid(row=0, column=1) | |
text_list = tk.Listbox(frame) | |
text_list.grid(row=1, column=0, columnspan=2, sticky="nsew") | |
frame2 = tk.Frame(root) | |
frame2.grid(row=0, column=1, sticky="nsew", padx=5, pady=5) | |
frame2.columnconfigure(0, weight=1) | |
frame2.rowconfigure(1, weight=1) | |
entry = tk.Entry(frame2) | |
entry.grid(row=0, column=0, sticky="ew") | |
entry.bind("<Return>", add_to_list) | |
entry_btn = tk.Button(frame2, text="Add", command=add_to_list) | |
entry_btn.grid(row=0, column=1) | |
text_list = tk.Listbox(frame2) | |
text_list.grid(row=1, column=0, columnspan=2, sticky="nsew") | |
root.mainloop() |
Thank you for great tutorial.
Now we have two frame but both frame are contain same variable name. How i can get first frame entry value?
Nice one
Thank you for great tutorial. Now we have two frame but both frame are contain same variable name. How i can get first frame entry value?
You have to use the other option of passing the function, which is using a lambda function so u can pass in different argument.
Nice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a great job well done, I also used the same library to build Test app with SQLite database.
To see the project
https://github.com/balobasheer