python tkinter create window code example
Example 1: how to make a tkinter window
from tkinter import *
mywindow = Tk()
mywindow.title("New Project")
mywindow.geometry("780x640")
mywindow.minsize(540, 420)
mywindow.configure(bg="blue")
mywindow.mainloop()
Example 2: 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 3: make a window tkinter
#!/usr/bin/python
import Tkinter
top = Tkinter.Tk()
top.mainloop()