我正在做一个项目,需要得到我的屏幕尺寸(我在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模块。
谢谢你们的回答和帮助。
1条答案
按热度按时间nwnhqdif1#
你可以使用这个:
width = root.winfo_screenwidth() height = root.winfo_screenheight()
这将提供您正在使用的屏幕的总尺寸。希望这对你有帮助!