tkinter basic program code example
Example 1: tkinter basic
from tkinter import Tk, Label, Button
class MyFirstGUI:
def __init__(self, master):
self.master = master
master.title("A simple GUI")
self.label = Label(master, text="This is our first GUI!")
self.label.pack()
self.greet_button = Button(master, text="Greet", command=self.greet)
self.greet_button.pack()
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
def greet(self):
print("Greetings!")
root = Tk()
my_gui = MyFirstGUI(root)
root.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: basic tkinter gui
import tkinter as tk
root = tk.Tk()
root.title("my title")
root.geometry('200x150')
root.configure(background='black')
root.mainloop()
Example 4: make a window tkinter
#!/usr/bin/python
import Tkinter
top = Tkinter.Tk()
top.mainloop()
Example 5: how to create tkinter window
import tkinter
master = tkinter.Tk()
master.mainloop()
Example 6: tkinter tutorial
import tkinter as tk
from tkinter import ttk
window=tk.Tk()
label=ttk.Label(window,text="My First App")
label.pack()
window.mainloop()