[파이썬] tkinter 전체 화면 모드와 창 크기 조절

Python offers a wide range of tools and libraries for GUI (Graphical User Interface) development, and tkinter is one of the most popular among them. With tkinter, you can create windows, buttons, labels, and other GUI elements to build interactive applications.

In this blog post, we will explore how to use tkinter to:

  1. Switch the application to full-screen mode.
  2. Resize the window dynamically.

Full-Screen Mode

Full-screen mode can be useful when you want to maximize the display area for your application. The tkinter library provides a attributes() method that allows you to manipulate the window attributes, including the -fullscreen flag to set it to full-screen mode.

Here’s an example:

import tkinter as tk

root = tk.Tk()
root.attributes("-fullscreen", True)

root.mainloop()

By setting the -fullscreen attribute to True, the root window will open in full-screen mode.

Resizing the Window

You may want to allow users to resize the window based on their preferences or adjust the layout of your application dynamically. To achieve this, tkinter provides the geometry() method, which allows you to set the initial size and the minimum and maximum width and height of the window.

Here’s an example:

import tkinter as tk

root = tk.Tk()
root.geometry("500x300")  # Initial size of the window

# Optional: Set the minimum and maximum width and height
root.minsize(200, 200)
root.maxsize(800, 600)

root.mainloop()

In the above example, the window will initially open with a size of 500x300 pixels. Additionally, the minimum width and height are set to 200x200 pixels, and the maximum width and height are set to 800x600 pixels.

Conclusion

In this blog post, we explored how to use tkinter in Python to switch an application to full-screen mode and resize the window dynamically. These features can enhance the user experience and make your application more flexible and responsive. With the power of tkinter, you can create visually appealing and functional GUI applications in Python.

Feel free to experiment with these concepts in your own tkinter projects and let your creativity shine! Happy coding!