Tkinter Window
Summary: in this tutorial, you’ll learn how to manipulate various attributes of a Tkinter window.
Let’s start with a simple program that consists of a window:

The root window has a title that defaults to tk . It also has three system buttons including Minimize, Maximize, and Close.
Let’s learn how to change the attributes of the root window.
Changing the window title
To change the window’s title, you use the title() method like this:
For example, the following changes the title of the root window to ‘Tkinter Window Demo’ :

To get the current title of a window, you use the title() method with no argument:
Changing window size and location
In Tkinter, the position and size of a window on the screen is determined by geometry.
The following shows the geometry specification:

In this specification:
- The width is the window’s width in pixels.
- The height is the window’s height in pixels.
- The x is the window’s horizontal position. For example, +50 means the left edge of the window should be 50 pixels from the left edge of the screen. And -50 means the right edge of the window should be 50 pixels from the right edge of the screen.
- The y is the window’s vertical position. For example, +50 means the top edge of the window should be 50 pixels below the top of the screen. And -50 means the bottom edge of the window should be 50 pixels above the bottom of the screen.
To change the size and position of a window, you use the geometry() method:
The following example changes the size of the window to 600×400 and the position of the window to 50 pixels from the top and left of the screen:
Sometimes, you may want to center the window on the screen. The following program illustrates how to do it:
- First, get the screen width and height using the winfo_screenwidth() and winfo_screenheight() methods.
- Second, calculate the center coordinate based on the screen and window width and height.
- Finally, set the geometry for the root window using the geometry() method.
If you want to get the current geometry of a window, you can use the geometry() method without providing any argument:
Resizing behavior
By default, you can resize the width and height of a window. To prevent the window from resizing, you can use the resizable() method:
The resizable() method has two parameters that specify whether the width and height of the window can be resizable.
The following shows how to make the window with a fixed size:

When a window is resizable, you can specify the minimum and maximum sizes using the minsize() and maxsize() methods:
Transparency
Tkinter allows you to specify the transparency of a window by setting its alpha channel ranging from 0.0 (fully transparent) to 1.0 (fully opaque):
The following example illustrates a window with 50% transparent:

Window stacking order
The window stack order refers to the order of windows placed on the screen from bottom to top. The closer window is on the top of the stack and it overlaps the one lower.
To ensure that a window is always at the top of the stacking order, you can use the -topmost attribute like this:
To move a window up or down of the stack, you can use the lift() and lower() methods:
The following example places the root window on top of all other windows. In other words, the root window is always on top:
Changing the default icon
Tkinter window displays a default icon. To change this default icon, you follow these steps:
- Prepare an image in the .ico format. If you have the image in other formats like png or jpg , you can convert it to the .ico format. There are many online tools that allow you to do it quite easily.
- Place the icon in a folder that can be accessible from the program.
- Call the iconbitmap() method of the window object.
The following program illustrates how to change the default icon to a new one:
Как сделать изменяемый заголовок в tkinter
Возможно ли сделать заголовок изменяемым, при открытии файла. К примеру при создании родительского окна сделать «название программы», а при загрузке какого-то файла, изменить текст в заголовке на «название программы — путь к загруженному файлу»
![]()
Собственно, root.title = build_new_title() позволит изменить заголовок.
Думаю, правильный вопрос — как запускать это по определенным событиям? В таком случае — собственно, смотреть в следующую сторону, видимо : http://younglinux.info/tkinter/event.php
![]()
Вот Вам примерчик изменения заголовка по нажатию разных кнопок. В рамках Ваших событий необходимо изменять root.title(»).
Вы очень непонятно cформулировали свой вопрос.
Очевидно,что никто вам не напишет дополнительный параметр или встроеннyю функцию,kоторая бы понималa,что вы открываете файл и озаглавливала бы окно соответствующим названием.Вы сами должны написать для этого код.
Вот пример простейшего обозревателя текстовых файлов,который меняет заголовок окна на путь к файлу с помощью метода title:
Допустим, что файл с текстом сохраняется через функцию xSaveAs :
Тогда заголовок можно изменить внутри функции через app.title()
и свойством title у asksaveasfilename:
![]()
Дизайн сайта / логотип © 2023 Stack Exchange Inc; пользовательские материалы лицензированы в соответствии с CC BY-SA . rev 2023.3.11.43304
Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.
Как изменить название окна в tkinter
Summary: in this tutorial, you’ll learn how to manipulate various attributes of a Tkinter window.
Let’s start with a simple program that consists of a window:

The root window has a title that defaults to tk . It also has three system buttons including Minimize, Maximize, and Close.
Let’s learn how to change the attributes of the root window.
Changing the window title
To change the window’s title, you use the title() method like this:
For example, the following changes the title of the root window to ‘Tkinter Window Demo’ :

To get the current title of a window, you use the title() method with no argument:
Changing window size and location
In Tkinter, the position and size of a window on the screen is determined by geometry.
The following shows the geometry specification:

In this specification:
- The width is the window’s width in pixels.
- The height is the window’s height in pixels.
- The x is the window’s horizontal position. For example, +50 means the left edge of the window should be 50 pixels from the left edge of the screen. And -50 means the right edge of the window should be 50 pixels from the right edge of the screen.
- The y is the window’s vertical position. For example, +50 means the top edge of the window should be 50 pixels below the top of the screen. And -50 means the bottom edge of the window should be 50 pixels above the bottom of the screen.
To change the size and position of a window, you use the geometry() method:
The following example changes the size of the window to 600×400 and the position of the window to 50 pixels from the top and left of the screen:
Sometimes, you may want to center the window on the screen. The following program illustrates how to do it:
- First, get the screen width and height using the winfo_screenwidth() and winfo_screenheight() methods.
- Second, calculate the center coordinate based on the screen and window width and height.
- Finally, set the geometry for the root window using the geometry() method.
If you want to get the current geometry of a window, you can use the geometry() method without providing any argument:
Resizing behavior
By default, you can resize the width and height of a window. To prevent the window from resizing, you can use the resizable() method:
The resizable() method has two parameters that specify whether the width and height of the window can be resizable.
The following shows how to make the window with a fixed size:

When a window is resizable, you can specify the minimum and maximum sizes using the minsize() and maxsize() methods:
Transparency
Tkinter allows you to specify the transparency of a window by setting its alpha channel ranging from 0.0 (fully transparent) to 1.0 (fully opaque):
The following example illustrates a window with 50% transparent:

Window stacking order
The window stack order refers to the order of windows placed on the screen from bottom to top. The closer window is on the top of the stack and it overlaps the one lower.
To ensure that a window is always at the top of the stacking order, you can use the -topmost attribute like this:
To move a window up or down of the stack, you can use the lift() and lower() methods:
The following example places the root window on top of all other windows. In other words, the root window is always on top:
Changing the default icon
Tkinter window displays a default icon. To change this default icon, you follow these steps:
- Prepare an image in the .ico format. If you have the image in other formats like png or jpg , you can convert it to the .ico format. There are many online tools that allow you to do it quite easily.
- Place the icon in a folder that can be accessible from the program.
- Call the iconbitmap() method of the window object.
The following program illustrates how to change the default icon to a new one:
Change Tkinter Window Title

In this tutorial, we will learn how to change the title bar of a tkinter window.
The title in tkinter refers to a name assigned to the application window. It is mostly found on the top of the application. For this, we can use the title() function.
We create a widget object using the Tk() function and use the title() function to add a title to this window.
In the above example, we can see our window with the title Hello_World .
If we want to change the text style, font size, or the color of the title, then it can’t be done using tkinter as the only purpose of tkinter is to provide a name that has its own size and style by default.
If we want to set the title on the tkinter frame, we have to use the function LabelFrame() , which helps us set the title on the frame. This function takes the font size and the text to be displayed as the inputs. Also, we can change the color of it.