tkinter geometry
时间: 2023-09-11 11:12:59 浏览: 69
Tkinter is a Python library that provides a way to create graphical user interfaces (GUIs). The `geometry` method in Tkinter is used to set or retrieve the dimensions and position of a window or widget.
To set the geometry of a window, you can use the `geometry` method with the following format:
```python
window.geometry("widthxheight+Xposition+Yposition")
```
Here, `width` and `height` are the dimensions of the window in pixels, while `Xposition` and `Yposition` represent the position of the window on the screen.
For example, to set the dimensions of a window to 500x300 pixels and position it at coordinates (100, 100), you can use:
```python
window.geometry("500x300+100+100")
```
To retrieve the current geometry of a window, you can use the `geometry` method without any arguments:
```python
current_geometry = window.geometry()
```
This will return a string representing the current geometry of the window.
Additionally, you can use the `winfo_geometry()` method to retrieve the current geometry of a widget within a window. For example:
```python
current_widget_geometry = widget.winfo_geometry()
```
This will return a string representing the current geometry of the widget.
I hope this helps! Let me know if you have any more questions.