Skip to content

Instantly share code, notes, and snippets.

@CoreyMSchafer
Created July 27, 2024 16:47
Show Gist options
  • Save CoreyMSchafer/558014ea68297f4fc89f46513260bb00 to your computer and use it in GitHub Desktop.
Save CoreyMSchafer/558014ea68297f4fc89f46513260bb00 to your computer and use it in GitHub Desktop.
Python Tkinter Tutorial - Part 1
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()
@balobasheer
Copy link

balobasheer commented Jul 27, 2024

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

@atiqur-rahman02
Copy link

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?

@SheriffMudasir
Copy link

Nice one

@SheriffMudasir
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment