windows 如何在python(tkinter)上获取屏幕尺寸

i7uaboj4  于 7个月前  发布在  Windows
关注(0)|答案(1)|浏览(58)

我正在做一个项目,需要得到我的屏幕尺寸(我在windows上工作)。我只是业余的python和工作与它的乐趣和大学的作品。
下面是我的第一个任意维度的代码:

from tkinter import *
import random as rd
import numpy as np
import time

class game :
    
    def __init__(self):
        self.screen = Tk()
        
        #screen size
        self.screen.geometry("900x500")

        #the rest is not essential to understand my problem
        self.screen.mainloop()
game()

字符串
我第一次尝试我在youtube上看到的东西,但缺少一个模块,所以我在stackoverflow上搜索并写道:

#begin : creation of an str of window dim
        #step 0 creation of "window"
        self.window = Gtk.Window()
        
        #step 1 obtention screen dim
        self.dim = window.get_screen()
        
        #step 2 obtention of height and length
        self.h = self.dim.height
        self.l = self.dim.length
        
        #step 3 str
        self.strdim = str(l) + "x" + str(h)
        #end


self.window = Gtk.Window()部分对我来说是未知的,因为我真的不知道Gtk代表什么(我猜它是一个别名),当我搜索它时,我只找到了C语言中的一个功能,但没有python模块。
谢谢你们的回答和帮助。

nwnhqdif

nwnhqdif1#

你可以使用这个:
width = root.winfo_screenwidth() height = root.winfo_screenheight()这将提供您正在使用的屏幕的总尺寸。
希望这对你有帮助!

相关问题