making gui in python code example

Example 1: create window with python

# basic setup
from tkinter import *

app = Tk() # the application itself
app.title("Test") # title of window

label = Label(app, text="Testing testing one, two, three") # creates label
label.pack() # adds the label to the window

app.mainloop() # this must go at the end of your window code

Example 2: tkinter tutorial

# check this code first.
from tkinter import *

app = Tk()
# The title of the project
app.title("The title of the project")
# The size of the window
app.geometry("400x400")

# Defining a funtion
def c():
    # Label
    m = Label(app, text="Text")
    m.pack()


# Button
l = Button(app, text="The text of the Butoon", command=c)
# Packing the Button
l.pack()
app.mainloop()
# Quick Note : 
# When you put a command you should not use parentheses
# l = Button(app, text="The text of the Butoon", command=c)
# l = Button(app, text="The text of the Butoon", command=c())

Example 3: python gui

import tkinter as tk
#Importing the main module
window = tk.Tk()
window.mainloop()

Example 4: how to create tkinter window

import tkinter
master = tkinter.Tk()
master.mainloop()

Tags:

Misc Example