2013-02-16 10 views

cevap

46

Bu cevap Rachel's answer dayanmaktadır deneyin. Onun kodu orijinal olarak işe yaramadı, ama biraz düzeltme yaparak hataları düzeltmeyi başarabiliyordum.

import tkinter as tk 


root = tk.Tk() # create a Tk root window 

w = 800 # width for the Tk root 
h = 650 # height for the Tk root 

# get screen width and height 
ws = root.winfo_screenwidth() # width of the screen 
hs = root.winfo_screenheight() # height of the screen 

# calculate x and y coordinates for the Tk root window 
x = (ws/2) - (w/2) 
y = (hs/2) - (h/2) 

# set the dimensions of the screen 
# and where it is placed 
root.geometry('%dx%d+%d+%d' % (w, h, x, y)) 

root.mainloop() # starts the mainloop 
21

bu

import tkinter as tk 


def center_window(width=300, height=200): 
    # get screen width and height 
    screen_width = root.winfo_screenwidth() 
    screen_height = root.winfo_screenheight() 

    # calculate position x and y coordinates 
    x = (screen_width/2) - (width/2) 
    y = (screen_height/2) - (height/2) 
    root.geometry('%dx%d+%d+%d' % (width, height, x, y)) 


root = tk.Tk() 
center_window(500, 400) 
root.mainloop() 

Source

+0

veya http://eurion.net/python-snippets/snippet/Center adresinde belirtebilirsiniz. Maksimum yararlılık için alternatif bir yöntem olan –

+1

için% 20window.html, girintinizi düzeltmek isteyebilirsiniz. – mgilson

+1

@RachelGallen: Bu kodun tamamen farklı bir araç seti için olduğunu biliyor musunuz? Bir titreme penceresini ortalamak için pyqt kullanamazsınız. –

5
root.geometry('250x150+0+0') 

kullanılması bu iki parametre Pencerenin genişliği ve yüksekliği. Son iki parametre x ve y ekran koordinatlarıdır. Gerekli x ve y koordinatlarını

İlgili konular