1#---------moving a Window in Center-----------#
2
3from tkinter import *
4
5window = Tk()
6
7window.title("Python GUI App")
8window.configure(width=500, height=300)
9window.configure(bg='lightgray')
10
11# move window center
12winWidth = window.winfo_reqwidth()
13winwHeight = window.winfo_reqheight()
14posRight = int(window.winfo_screenwidth() / 2 - winWidth / 2)
15posDown = int(window.winfo_screenheight() / 2 - winwHeight / 2)
16window.geometry("+{}+{}".format(posRight, posDown))
17
18window.mainloop()
1import tkinter
2from tkinter import *
3
4#this makes the window
5window = Tk()
6#title
7window.title("My Window")
8#change the size to whatever you want too
9window.configure(width = 800, height = 800)
10#change the background color to whatever you want too
11window.configure(bg = 'black')
12#this runs the window
13window.mainloop()
14
15#simple way to a window in python
1import tkinter as tk
2
3
4def new_window1():
5 " new window"
6 try:
7 if win1.state() == "normal": win1.focus()
8 except NameError as e:
9 print(e)
10 win1 = tk.Toplevel()
11 win1.geometry("300x300+500+200")
12 win1["bg"] = "navy"
13 lb = tk.Label(win1, text="Hello")
14 lb.pack()
15
16
17win = tk.Tk()
18win.geometry("200x200+200+100")
19button = tk.Button(win, text="Open new Window")
20button['command'] = new_window1
21button.pack()
22win.mainloop()
23
1#If using tkinter
2import tkinter as tk
3from tkinter import*
4#Window creating
5root = tk.Tk()
6# Defining name
7name = "First window"
8# Setting window
9root.title(name)
10# IF want to use geometry So let me tell that no need of that at all
11# Tkinter sets the window according to data or things inside it
12# Adding button
13Button bt1 = Button(root, text = "Simple click");
14# Making function
15def doer():
16 # Print is for console
17 print("Did well");
18# Adding button with function
19Button bt2 = Button(root, text = "Function", command = doer)
20# If you will add () it after brackets it will run automatically
21# Adding buttons
22bt1.pack()
23bt2.pack()
24root.mainloop()
25# This can show error If using pycharm reformat file
26# Set it as you are best
1import pygame
2pygame.init()
3
4sh = int(500)
5sw = int(500)
6win = pygame.display.set_mode((sh, sw))
7
8run = True
9while run:
10 pygame.time.delay(100)
11 for event in pygame.event.get():
12 if event.type == pygame.QUIT:
13 run = False
14