Desktop Programming in Python With Tkinter
Desktop Programming in Python With Tkinter
Frames in tkinter
A Frame is a container that groups related widgets together. It helps organize the layout of an
application and makes it easier to manage and style widgets.
import tkinter as tk
root = tk.Tk()
root.title("Frame Example")
# Create a frame
frame = tk.Frame(root, bg="lightblue", padx=10, pady=10)
frame.pack(padx=20, pady=20)
root.mainloop()
import tkinter as tk
root = tk.Tk()
label1 = tk.Label(root, text="Label 1")
label1.pack(side="top")
root.mainloop()
root = tk.Tk()
label1 = tk.Label(root, text="Label 1")
label1.grid(row=0, column=0)
root.mainloop()
import tkinter as tk
root = tk.Tk()
root.title("Calculator")
def button_click(value):
entry.insert(tk.END, value)
def calculate():
try:
result = eval(entry.get())
entry.delete(0, tk.END)
entry.insert(0, result)
except Exception as e:
entry.delete(0, tk.END)
entry.insert(0, "Error")
root.mainloop()
app = ctk.CTk()
app.title("CustomTkinter Example")
app.mainloop()
4. Flet
Features:
Allows building interactive desktop, web, and mobile apps using Python.
Built on Flutter, giving access to rich UI components.
Hot-reload for rapid development.
Cross-platform support for Windows, macOS, Linux, and the web.
Use Case:
Ideal for developers wanting to create multi-platform applications with a consistent
look and feel using Python.
Example Usage:
import flet as ft
def main(page: ft.Page):
page.title = "Flet Example"
page.add(ft.Text("Hello, Flet!"))
ft.app(target=main)