Python-written Tkinter program Screen Center method _python

Source: Internet
Author: User

This article applies to the scenario: you want to use the Tkinter development interface program and the screen center, but did not find the appropriate API.

These two days play tkinter, feel good, is the screen centered this problem on the Internet search for a long time also did not
Find the answer, there is no way, look at its documents, in their own way to achieve.

The way is to get the initialized form size and screen size, and then calculate the gross value.
Here's the code:

Copy Code code as follows:

#! /usr/bin/python
'''
File:screenCenter.pyw
Author:mike
E-mail:mike_zhang@live.com
'''
From Tkinter Import *

RT = Tk ()
Rt.resizable (False,false)
Rt.title ("Screen Center")

Rt.update () # Update window, must do
Curwidth = Rt.winfo_reqwidth () # Get current width
Curheight = Rt.winfo_height () # Get current height
Scnwidth,scnheight = Rt.maxsize () # Get screen width and height
# now generate configuration information
tmpcnf = '%dx%d+%d+%d '% (Curwidth,curheight,
(scnwidth-curwidth)/2, (Scnheight-curheight)/2)
Rt.geometry (TMPCNF)
Rt.mainloop ()

Well, that's all, I hope to help you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.