How to create a window with Tkinter

  • Italian
  • English
Creare una Finestra in Python

🐍 Come creare una finestra in Python

Con Tkinter, la libreria grafica inclusa in Python, puoi creare una finestra in pochi secondi.

✅ Codice base:

import tkinter as tk

finestra = tk.Tk()
finestra.title("La mia prima finestra")
finestra.geometry("400x300")
finestra.mainloop()

📌 Spiegazione veloce:

  • import tkinter as tk → Importa la libreria grafica.
  • tk.Tk() → Crea la finestra.
  • title() → Imposta il titolo della finestra.
  • geometry() → Imposta dimensioni (larghezza x altezza).
  • mainloop() → Mantiene aperta la finestra.

🎉 Ora puoi aggiungere bottoni, etichette, immagini e molto altro!

Create a Window in Python with Pygame

đŸ•šī¸ How to Create a Window in Python with Pygame

Want to create a simple window using Pygame? Here’s the basic code to get started with interactive graphics or game development.

✅ Example Code:

import pygame
import sys

# Initialize Pygame
pygame.init()

# Create the window (width x height)
screen = pygame.display.set_mode((600, 400))

# Set the title
pygame.display.set_caption("My Pygame Window")

# Main loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

# Clean up
pygame.quit()
sys.exit()

📌 What does this code do?

  • pygame.init() → Starts Pygame.
  • set_mode() → Creates a window with your chosen size.
  • set_caption() → Sets the title bar text.
  • pygame.event.get() → Checks for window events (like close).
  • pygame.quit() → Closes the window properly.

🎮 From here, you can start drawing, adding images, handling input, or building full games!


Subscribe to the newsletter for updates
Tkinter templates

Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Claude's Games

Arkanoid
Platform 2d

1. Memory game

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Advertisement