python - 如何使用 tkinter 设置 3 个或更多帧?
问题描述
我正在尝试这个,所以我可以在 medFrame 中放置按钮,但它们出现在 topFrame 中。使用 topFrame 时,按钮靠在屏幕顶部,看起来很糟糕,所以我想这可以通过使用第三个框架来解决。
from tkinter import *
root = Tk()
root.title('BulletHead')
root.attributes('-fullscreen', True)
root.resizable(width = NO, height=NO)
topFrame=Frame(root)
topFrame.pack(side=TOP)
medFrame=Frame(root)
medFrame.pack()
botFrame = Frame(root)
botFrame.pack(side=BOTTOM)
botonJugar = Button(medFrame, text = 'Jugar')
botonJugar.bind("<Button-1>",jugar)
botonJugar.pack()
botonTabla = Button(medFrame, text = 'Tabla de puntajes')
botonTabla.bind("<Button-1>",tabla)
botonTabla.pack()
root.mainloop()
解决方案
元素已成功添加到中间帧,但它们看起来好像在顶部帧中,因为topFrame
和botFrame
没有尺寸,因此它们不会出现(除非您可以感知一个像素)。要为中间框架获得一些间距,您需要为其他框架提供一些尺寸。试试这个给中间框架一些间距:
topFrame=Frame(root, height=200, width=200)
botFrame = Frame(root, height=200, width=200)
对此的替代方法是检查一些其他选项,以使用仅一帧的包几何管理器来获得所需的结果。特别是该expand=
选项有助于在窗口中居中对象。
from tkinter import *
root = Tk()
root.title('BulletHead')
root.attributes('-fullscreen', True)
root.resizable(width = NO, height=NO)
medFrame=Frame(root)
medFrame.pack(expand=True)
botonJugar = Button(medFrame, text = 'Jugar')
botonJugar.bind("<Button-1>",jugar)
botonJugar.pack()
botonTabla = Button(medFrame, text = 'Tabla de puntajes')
botonTabla.bind("<Button-1>",tabla)
botonTabla.pack()
root.mainloop()
推荐阅读
- c# - 我如何使屏幕区域/按钮能够移动播放器?
- c++ - 使用带有前向声明的结构
- pine-script - Tradingview Pine Script - 数组中的变量以绘制当前代码
- react-native - Expo Config Mods - DangerouslyModify MainApplication.java
- c# - 使用反射获取BaseType类DeclaredFields
- android - 无法解决:com.github.PhilJay:MPAndroidChart:v3.1.0
- python - 在 auto-py-to-exe 之后 Python 程序运行方式不同
- azure-devops - 当有新版本可用时,如何自动取消正在等待 POST-DEPLOYMENT 批准的版本?
- python - Groupby Roll up 或 Roll Down 用于任何类型的聚合
- cuda - 通过 UUID 设置 CUDA 设备