tkinter tutorials easy code example
Example 1: how to make a tkinter window
from tkinter import *
mywindow = Tk()
mywindow.title("New Project")
mywindow.geometry("780x640")
mywindow.minsize(540, 420)
mywindow.configure(bg="blue")
mywindow.mainloop()
Example 2: how to create a tkinter window
from tkinter import *
new_window = Tk()
new_window.title("My Python Project")
new_window.geometry("200x150")
new_window.configure(bg = "red")
new_window.mainloop()
Example 3: tkinter tutorial
from tkinter import *
app = Tk()
app.title("The title of the project")
app.geometry("400x400")
def c():
m = Label(app, text="Text")
m.pack()
l = Button(app, text="The text of the Butoon", command=c)
l.pack()
app.mainloop()
Example 4: gui in tkinter
from tkinter import *
import os
window = Tk()
window.geometry("450x450")
window.title("Gui App")
window.configure(bg="powder blue")
filename = Entry(window, width=75)
filename.pack()
def runFile():
try:
os.startfile(filename.get())
except:
error = Label(window, text=f"No file found as {filename.get}")
error.pack()
open_file_button = Button(window, text="Run File", command=runFile)
open_file_button.pack()
window.mainloop()
Example 5: tkinter tutorial
import tkinter as tk
window = tk.Tk()
frame_a = tk.Frame()
frame_b = tk.Frame()
label_a = tk.Label(master=frame_a, text="I'm in Frame A")
label_a.pack()
label_b = tk.Label(master=frame_b, text="I'm in Frame B")
label_b.pack()
frame_a.pack()
frame_b.pack()
window.mainloop()