You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
729 B
23 lines
729 B
import tkinter as tk
|
|
from screeninfo import get_monitors
|
|
|
|
# 创建Tkinter窗口
|
|
window = tk.Tk()
|
|
window.title("设置按钮尺寸为当前屏幕的百分之85")
|
|
window.geometry('190x160')
|
|
def jis():
|
|
# 获取当前屏幕的宽度和高度
|
|
monitors = get_monitors()
|
|
screen_width = monitors[0].width
|
|
screen_height = monitors[0].height
|
|
|
|
# 计算按钮的宽度和高度
|
|
button_width = int(screen_width * 0.85)
|
|
button_height = int(screen_height * 0.85)
|
|
# 打印按钮的宽度和高度
|
|
print(f"按钮的尺寸:{button_width}x{button_height}")
|
|
# 创建一个按钮,并设置尺寸
|
|
button = tk.Button(window, text="按钮", command=jis)
|
|
button.pack()
|
|
# 运行Tkinter事件循环
|
|
window.mainloop() |