1from tkinter import Tk, Label, Button
2
3class MyFirstGUI:
4 def __init__(self, master):
5 self.master = master
6 master.title("A simple GUI")
7
8 self.label = Label(master, text="This is our first GUI!")
9 self.label.pack()
10
11 self.greet_button = Button(master, text="Greet", command=self.greet)
12 self.greet_button.pack()
13
14 self.close_button = Button(master, text="Close", command=master.quit)
15 self.close_button.pack()
16
17 def greet(self):
18 print("Greetings!")
19
20root = Tk()
21my_gui = MyFirstGUI(root)
22root.mainloop()
23
1#!/usr/bin/python
2
3import Tkinter
4top = Tkinter.Tk()
5# Code to add widgets will go here...
6top.mainloop()
1import tkinter as tk
2root = tk.Tk()
3root.title("my title")
4root.geometry('200x150')
5root.configure(background='black')
6
7# enter widgets here
8
9root.mainloop()
1from tkinter import *
2import os
3
4# window
5window = Tk()
6window.geometry("450x450")
7window.title("Gui App")
8window.configure(bg="powder blue")
9
10# Enter or user input in tkinter
11filename = Entry(window, width=75)
12filename.pack()
13
14# Run file Function
15
16def runFile():
17 try:
18 os.startfile(filename.get())
19
20 except:
21 error = Label(window, text=f"No file found as {filename.get}")
22 error.pack()
23
24 # Run file button
25open_file_button = Button(window, text="Run File", command=runFile)
26open_file_button.pack()
27
28window.mainloop()
29