Python: tkinter窗口屏幕居中,设置窗口最大,最小尺寸
2017-07-21 15:17
1156 查看
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()
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窗口屏幕居中,设置窗口最大,最小尺寸
- Python: tkinter窗口屏幕居中,设置窗口最大,最小尺寸
- WTL 设置主窗口最小/最大尺寸
- WM_GETMINMAXINFO 设置窗口最大最小尺寸(无边框窗口不遮挡任务栏)
- MFC 窗口最大尺寸与最小尺寸设置
- 设置窗口的最大最小尺寸
- Qt窗口屏幕居中显示以及设置大小
- 控制窗口的最大最小尺寸
- Python写的Tkinter程序屏幕居中方法
- Qt窗口屏幕居中显示以及设置大小
- MFC 控制窗口最大最小尺寸
- 玩转 Javascript 弹出窗口, 居中与居角扩大窗口至屏幕最大值
- MFC,调整窗口大小限制大小,设置窗口的最大|最小宽度与高度
- Js弹出窗口、居中、居角、扩大窗口至屏幕最大的代码
- 如何控制窗口框架的最大最小尺寸
- 如何控制窗口框架的最大最小尺寸
- MFC中静态与动态设置窗体最大与最小尺寸
- Javascript 弹出窗口, 居中与居角扩大窗口至屏幕最大值
- Qt窗口屏幕设置大小与居中显示
- 限制窗口的最大尺寸和最小尺寸