以下是一个示例代码,用于在不同尺寸的显示屏下显示不同的类别:
import tkinter as tk
def get_screen_size():
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.destroy()
return screen_width, screen_height
def get_category(screen_width):
if screen_width >= 1920:
return "大屏幕"
elif screen_width >= 1280:
return "中屏幕"
else:
return "小屏幕"
# 获取屏幕尺寸
screen_width, screen_height = get_screen_size()
# 获取类别
category = get_category(screen_width)
print("当前屏幕类别:", category)
这个代码使用了tkinter
库来获取屏幕的宽度和高度。通过比较屏幕宽度,可以确定显示屏的类别。在示例中,大屏幕的宽度大于等于1920,中屏幕的宽度大于等于1280,其他宽度的屏幕被认为是小屏幕。
你可以根据实际需要修改类别的划分标准和显示方式。