Creating a Simple Window in Tkinter

Posted by

Création d’une fenêtre simple dans tkinter

Création d’une fenêtre simple dans tkinter

Python’s tkinter module provides a simple way to create graphical user interfaces. One of the basic tasks you can do with tkinter is to create a simple window. Below is an example of how you can create a simple window using tkinter:

import tkinter as tk

# Create a simple window
root = tk.Tk()
root.title("Ma première fenêtre tkinter")
root.geometry("400x300")

# Run the window
root.mainloop()

Explanation of the code:

  • We first import the tkinter module as tk.
  • We create a root window using the tk.Tk() method.
  • We set the title of the window using the title() method.
  • We set the size of the window using the geometry() method.
  • Finally, we start the event loop using the mainloop() method, which will display the window on the screen.

When you run this code, you will see a simple window with the title “Ma première fenêtre tkinter” and dimensions of 400×300 pixels.

Creating a simple window in tkinter is just the beginning. You can customize the window further by adding buttons, labels, text fields, and other widgets to create more complex GUIs. Explore the tkinter documentation to learn more about the capabilities of this module.