2013-02-16 7 views
32

स्क्रीन आयामों के आधार पर, मैं एक टिंकर विंडो कहां खोल सकता हूं? मैं इसे बीच में खोलना चाहता हूं।यह निर्दिष्ट करने के लिए कि टिंकर विंडो कहां खुलती है?

+0

[एक उत्तर] (http://stackoverflow.com/a/10018670/1217270) –

उत्तर

46

इस उत्तर Rachel's answer पर आधारित है की कोशिश करो। उसका कोड मूल रूप से काम नहीं करता था, लेकिन कुछ tweaking के साथ मैं गलतियों को ठीक करने में सक्षम था।

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

इस

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

निर्दिष्ट कर सकते हैं या http://eurion.net/python-snippets/snippet/Center देखें अधिकतम उपयोगिता के लिए वैकल्पिक विधि –

+1

के लिए% 20window.html, आप अपने इंडेंटेशन को ठीक करना चाहेंगे। – mgilson

+1

@RachelGallen: क्या आपको एहसास है कि कोड एक पूरी तरह से अलग टूलकिट के लिए है? आप एक tkinter खिड़की केंद्र के लिए pyqt का उपयोग नहीं कर सकते हैं। –

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

उपयोग इस पहले दो मापदंडों चौड़ाई और खिड़की की ऊंचाई है। पिछले दो पैरामीटर एक्स और वाई स्क्रीन निर्देशांक हैं। आप आवश्यक x और y निर्देशांक

संबंधित मुद्दे