tkiner获取屏幕分辨率
时间: 2023-07-30 22:10:54 浏览: 96
要使用Tkinter获取屏幕分辨率,您可以使用Tkinter库中的Tk()方法和winfo_screenwidth()和winfo_screenheight()方法。以下是获取屏幕分辨率的示例代码:
``` python
import tkinter as tk
# 创建一个Tkinter窗口
root = tk.Tk()
# 获取屏幕分辨率
screen_width = root.winfo_screenwidth()
screen_height = root.winfoheight()
print("屏幕分辨率为 %sx%s" % (screen_width, screen_height))
# 关闭Tkinter口
root.destroy()
```
该代码将打印出您屏幕的分辨率,并在结束后关闭Tkinter窗口。
相关问题
tkinter获取屏幕大小
你可以使用Tkinter的`Tk()`方法创建一个窗口对象,然后通过`winfo_screenwidth()`和`winfo_screenheight()`方法获取屏幕的宽度和高度。下面是一个示例代码:
```python
import tkinter as tk
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
print("屏幕宽度:", screen_width)
print("屏幕高度:", screen_height)
root.mainloop()
```
该代码将创建一个无窗口的Tkinter窗口对象,并获取屏幕的宽度和高度。
python tkinter获取屏幕大小
使用Tkinter的方法,可以通过以下代码获取屏幕大小:
```python
import tkinter as tk
root = tk.Tk()
# 获取屏幕大小
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
print("屏幕宽度:", screen_width)
print("屏幕高度:", screen_height)
```
在这个例子中,我们创建了一个Tkinter的根窗口,并使用winfo_screenwidth()和winfo_screenheight()方法获取屏幕的宽度和高度。最后,我们将结果打印到控制台中。