1

I am currently trying to add a feature to my program where the programs resolution will change at every launched based on your screen resolution. I have run into an issue though.

It first states that my variables, width and height are undefined. I then modified my code and it then says bad geometry specifier.

Undefined Variables:

    pygame.mixer.init()   
    app = minecraftGuideApp()

    #Window Definitions
    screen_width = app.winfo_screenwidth()
    screen_height = app.winfo_screenheight()

    if screen_width == "1366" and screen_height == "768":
            width = "1280"
            height = "720"

    app.geometry(width, height)
    app.mainloop()

Bad Geometry Specifier:

    pygame.mixer.init()   
    app = minecraftGuideApp()

    #Window Definitions
    screen_width = app.winfo_screenwidth()
    screen_height = app.winfo_screenheight()

    width = screen_width
    height = screen_height

    app.geometry((width, height))
    app.mainloop()

I am still learning Python, so please excuse any dumb mistakes I am making.

What am I doing wrong though?

Austin Hargis
  • 139
  • 1
  • 1
  • 12

1 Answers1

2

The syntax for a call to the Tkinter geometry method is given at this reference. You need to compose a geometry string in the proper syntax

which is:

"%dx%d%+d%+d" % (width, height, xoffset, yoffset)

In your case the call should look like

app.geometry("1280x720")

paisanco
  • 4,098
  • 6
  • 27
  • 33
  • When I run it, I get an error saying that xoffset and yoffset are undefined, which I understand they were. I set both of them to 0. I assume the offset is where onscreen the window displays when the program runs? – Austin Hargis May 10 '15 at 16:33
  • Depends on where you want the window to be. [This previous question](http://stackoverflow.com/questions/3352918/how-to-center-a-window-on-the-screen-in-tkinter) discusses setting the offsets for centering the window on the screen for instance. – paisanco May 10 '15 at 16:42
  • Ah, thank you! My program works the way I wish it to know. Now I just have to add support for if the user has more than one monitor. – Austin Hargis May 10 '15 at 16:56