how to make python open a window code example
Example 1: how to open a window in python
import tkinter as tk
def new_window1():
" new window"
try:
if win1.state() == "normal": win1.focus()
except NameError as e:
print(e)
win1 = tk.Toplevel()
win1.geometry("300x300+500+200")
win1["bg"] = "navy"
lb = tk.Label(win1, text="Hello")
lb.pack()
win = tk.Tk()
win.geometry("200x200+200+100")
button = tk.Button(win, text="Open new Window")
button['command'] = new_window1
button.pack()
win.mainloop()
Example 2: how to make a screen in python
import pygame
pygame.init()
sh = int(500)
sw = int(500)
win = pygame.display.set_mode((sh, sw))
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False