Tkinter widgets code example

Example 1: python gui

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

Example 2: gui in tkinter

from tkinter import *
import os

# window
window = Tk()
window.geometry("450x450")
window.title("Gui App")
window.configure(bg="powder blue")

# Enter or user input in tkinter
filename = Entry(window, width=75)
filename.pack()

# Run file Function

def runFile():
  try:
  	os.startfile(filename.get())
   
  except:
    error = Label(window, text=f"No file found as {filename.get}")
    error.pack()
    
 # Run file button
open_file_button = Button(window, text="Run File", command=runFile)
open_file_button.pack()

window.mainloop()

Example 3: how to create tkinter window

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

Example 4: tkinter widgets overview

.label configure -textvariable resultContents
set resultContents "New value to display"