0

I'm working on a project and need to get the dimensions of my screen (I'm working on windows). I'm only amateur on python and work with it for fun and university works.

Here is my first code with arbitrary dimensions :

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()

I fristly tried something I saw on youtube but a module was missing so I searched here on stackoverflow and wrote that:

        #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

The self.window = Gtk.Window() part is unknowed to me because I really don't know what Gtk stands for (I guessed it was an alias) and when I search for it I only find about a feature in C language but no module on python.

Thank y'all for your responses and help.

Moh
  • 1
  • 1
    Research the `winfo_screenwidth` and `winfo_screenheight` methods on the root window. – Bryan Oakley Jul 21 '23 at 18:58
  • Does this answer your question? [How can I get the screen size in Tkinter?](https://stackoverflow.com/questions/3949844/how-can-i-get-the-screen-size-in-tkinter) – toyota Supra Jul 21 '23 at 19:11

0 Answers0