Interface centering

J

Jah_Alarm

sorry 4 the sillu question.

I've designed a GUI. How can I center on the screen? (i.e. it's always
launched in the center of the screen)

cheers,

Alex
 
C

Chris Rebert

sorry 4 the sillu question.

I've designed a GUI. How can I center on the screen? (i.e. it's always
launched in the center of the screen)

Which GUI toolkit did you use?

Cheers,
Chris
 
P

Peter Otten

Jah_Alarm said:
hi, I'm using Tkinter

cheers,

Alex

First hit googling for 'tkinter center' is

http://www.daniweb.com/forums/thread66181.html

With minor stylistic changes this becomes:

from Tkinter import *

def center_window(w, h):
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws//2) - (w//2)
y = (hs//2) - (h//2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))

root = Tk()
center_window(500, 300)
root.mainloop()

A good basic source for Tkinter programming is

http://infohost.nmt.edu/tcc/help/pubs/tkinter/

Geometry strings are explained here:

http://infohost.nmt.edu/tcc/help/pubs/tkinter/std-attrs.html#geometry

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top