The geometry() method sets a size for the window and positions it on the screen. The first two parameters are the width and height of the window. The last two parameters are x and y screen coordinates. 这个geometry()方法给窗口设置了一个大小并将它放在在屏幕上。前两个参数分别是宽和高。后...
window_height = 200 # 获取屏幕尺寸screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() # 计算窗口坐标 center_x = int(screen_width/2 - window_width / 2) center_y = int(screen_height/2 - window_height / 2) root.geometry(f'{window_width}x{window_height...
# 设置窗口标题# 设置窗口尺寸window_width = 300window_height = 200# 获取屏幕尺寸screen_width = root.winfo_screenwidth()screen_height = root.winfo_screenheight()# 计算窗口坐标center_x = int(screen_width/2 - window_width / 2)center_y = int(screen_height/2 - window_height / 2)root.geo...
text='确定',width=15,height=1,command=lambda:ON_SUBMIT(TextBoxUserName,ListboxUser))ButtonSubmit.place(x=20,y=80)ListboxUser=Listbox(APP,height=20,width=30)ListboxUser.place(x=20,y=120)foritemin['张三','李四','王五']:ListboxUser.insert(0,item)SetWindow2CenterByScreen(APP,APP...
window_y = root.winfo_screenheight() "设置窗口大小参数" WIDTH = 500 HEIGHT = 350 "获取窗口左上角的X, Y坐标,用来设置窗口的放置位置为屏幕的中间。" x = (window_x - WIDTH) / 2 y = (window_y - HEIGHT) / 2 root.geometry(f'{WIDTH}x{HEIGHT}+{int(x)}+{int(y)}') ...
winfo_screenwidth():屏幕宽度; winfo_screenheight():屏幕高度。 下面的程序将窗口显示在屏幕中央。 root =Tk() screenWidth=root.winfo_screenwidth() screenHeight=root.winfo_screenheight() w= 300h= 160x= (screenWidth - w) / 2y= (screenHeight -h) / 2root.geometry("%dx%d+%d+%d"%(w,h...
self.choose_day_frame=tk.Frame(master=self.init_window_name)# 创建存放单选组件的容器 self.choose_day_frame.grid(padx=20,pady=0,row=2,column=0,sticky=tk.W)self.choose_number_frame=tk.Frame(master=self.init_window_name)# 创建存放复选组件的容器 ...
导入经典和新的主题小部件:import tkinter as tk from tkinter import ttk 「创建经典标签和新的主题...
ttk.Button(f, text='>', width=10, command=self.on_next).pack(side=LEFT, padx=10) def center(self): """窗口居中""" self.update() # 更新显示以获取最新的窗口尺寸 scr_w = self.winfo_screenwidth() # 获取屏幕宽度 scr_h = self.winfo_screenheight() # 获取屏幕宽度 ...
window=tk.Tk()window.title('c语言中文网')# 设置窗口大小变量 width=300height=300# 窗口居中,获取屏幕尺寸以计算布局参数,使窗口居屏幕中央 screenwidth=window.winfo_screenwidth()screenheight=window.winfo_screenheight()size_geo='%dx%d+%d+%d'%(width,height,(screenwidth-width)/2,(screenheight-heig...