import tkinter as tk def center_window(root, width=300, height=200): # 获取屏幕宽度和高度 screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() # 计算窗口的x和y坐标,使得窗口居中 x = (screen_width
import tkinter as tkroot = tk.Tk()defclose_window(): root.destroy()defcenter_window(root, width, height): screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() x = (screen_width / 2) - (width / 2) y = (screen_height / 2) - (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...
如果你对窗口的大小和位置有进一步的要求,可以尝试以下代码: # 将窗口居中显示importtkinterastkdefcenter_window(root,width=300,height=200):screen_width=root.winfo_screenwidth()screen_height=root.winfo_screenheight()x=(screen_width-width)//2y=(screen_height-height)//2root.geometry(f"{width}x{heig...
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) ...
最简单(但可能不准确)的方法是使用 tk::PlaceWindow ,它将顶层窗口的 路径名 作为参数。主窗口的路径名是 . import tkinter root = tkinter.Tk() root.eval('tk::PlaceWindow . center') second_win = tkinter.Toplevel(root) root.eval(f'tk::PlaceWindow {str(second_win)} center') root.mainloop(...
MainWindow类: 职责: 方法: Point类: 主执行部分: 完整代码: 总结: 连连看小游戏:用Python Tkinter打造的精彩游戏体验 在丰富多彩的游戏世界中,连连看作为一种经典的解谜游戏一直备受欢迎。连连看的玩法简单却富有挑战性,通过消除相同图标的配对,玩家可以不断地挑战自己的观察力和反应速度。
调用api showwindow 可以? 小搁浅 白丁 1 把tk窗口居中的函数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 - he...
defcenter_window(root:tk.Tk,w,h):# 获取屏幕 宽、高 ws=root.winfo_screenwidth()hs=root.winfo_screenheight()# 计算 x,y 位置 x=(ws/2)-(w/2)y=(hs/2)-(h/2)root.geometry('%dx%d+%d+%d'%(w,h,x,y)) 整合上述代码 代码语言:javascript ...
screen_height=root.winfo_screenheight()#计算窗口的宽度和高度window_width = 400#窗口宽度window_height = 200#窗口高度#计算窗口放置的位置x = (screen_width - window_width) // 2y= (screen_height - window_height) // 2#设置窗口的位置root.geometry(f"{window_width}x{window_height}+{x}+{y}...