Python:tkinter窗口屏幕居中,设置窗口最大,最小尺寸实例-创新互联

我就废话不多说了。大家直接看代码吧!

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站制作、成都做网站、外贸营销网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的玛曲网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
#!/usr/bin/env python
#coding=utf-8
'''
  窗口屏幕居中,设置窗口大,最小尺寸...
  版权所有 2014 yao_yu (http://blog.csdn.net/yao_yu_126)
  本代码以MIT许可协议发布
  2014-04-15 创建
'''
 
import tkinter as tk
from tkinter  import ttk
 
def get_screen_size(window):
  return window.winfo_screenwidth(),window.winfo_screenheight()
 
def get_window_size(window):
  return window.winfo_reqwidth(),window.winfo_reqheight()
 
def center_window(root, width, height):
  screenwidth = root.winfo_screenwidth()
  screenheight = root.winfo_screenheight()
  size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
  print(size)
  root.geometry(size)
 
root = tk.Tk()
root.title('测试窗口')
center_window(root, 300, 240)
root.maxsize(600, 400)
root.minsize(300, 240)
ttk.Label(root, relief = tk.FLAT, text = '屏幕大小(%sx%s)\n窗口大小(%sx%s)' % (get_screen_size(root) + get_window_size(root))).pack(expand = tk.YES)
tk.mainloop()

网站栏目:Python:tkinter窗口屏幕居中,设置窗口最大,最小尺寸实例-创新互联
链接地址:http://ybzwz.com/article/ddjocs.html