how to make a python gui code example
Example 1: create window with python
from tkinter import *
app = Tk()
app.title("Test")
label = Label(app, text="Testing testing one, two, three")
label.pack()
app.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: python basic gui
from tkinter import *
def click():
try:
text_info_1 = float(text1.get())
text_info_2 = float(text2.get())
except Exception as e:
text1.delete(0, END)
text2.delete(0, END)
text3.delete(0, END)
text3.insert(0, f'Error: {e}')
return
text3.delete(0, END)
text3.insert(0, text_info_1 + text_info_2)
root = Tk()
root.geometry('300x400')
root.title('Poop')
label1 = Label(root, text='Write something!')
label1.pack()
spacing1 = Label(root)
spacing1.pack()
text1 = Entry(root)
text1.pack(ipadx=20)
spacing2 = Label(root, text='+')
spacing2.pack()
text2 = Entry(root)
text2.pack(ipadx=20)
spacing3 = Label(root)
spacing3.pack()
button = Button(root, text='Click me!', command=click)
button.pack()
spacing4 = Label(root)
spacing4.pack()
text3 = Entry(root)
text3.pack(ipadx=60)
root.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()