python - TKinter - 按钮不是连续的?
问题描述
我尝试将这 2 个按钮 ia 放在 Dropbox 下方 -
但正如您在图片中看到的 - 按钮不在同一行。这是我为输出设置网格的代码的一部分:
myB = Button(root,text="Generate",padx=20,pady=10,command=show)
myB2 = Button(root,text="Reset",padx=20,pady=10,command=reset)
drop.grid(row=0,column=0, columnspan=2)
drop2.grid(row=1,column=0, columnspan=2)
drop3.grid(row=2,column=0, columnspan=2)
myB.grid(row=3,column=0)
myB2.grid(row=4,column=1)
任何想法为什么这不能按预期工作?
解决方案
为了匹配您的图像,代码需要看起来像这样。
root.rowconfigure(0, weight = 1)
root.columnconfigure(0, weight = 1)
root.rowconfigure(1, weight = 1)
root.columnconfigure(1, weight = 1)
root.rowconfigure(2, weight = 1)
myB = Button(root, text = "Generate", padx = 20, pady = 10, command = show)
myB2 = Button(root, text = "Reset", padx = 20, pady = 10, command = reset)
# sticky needed for resizing with window
drop.grid(row = 0, column = 0, columnspan = 2, sticky = tk.NSEW)
drop2.grid(row = 1, column = 0, columnspan = 2, sticky = tk.NSEW)
drop3.grid(row = 2, column = 0, columnspan = 2, sticky = tk.NSEW)
# This will make buttons 'float' otherwise un-rem sticky
myB.grid(row = 3, column = 0) #, sticky = tk.NSEW)
myB2.grid(row = 3, column = 1) #, sticky = tk.NSEW)
推荐阅读
- javascript - 如何在socket.io中始终加入同一个房间?
- summernote - Summernote 在文件选择时调用上传图片而不是插入图片
- r - 使用 `scales='free_y'` 进行缩放不适用于 `facet_grid`
- swift - 使用大标题导航栏时,为什么 UINavigationBar 动画不正确?
- python - “Int”对象在 Discord.py 命令上没有属性“id”错误
- javascript - Onclick 事件谷歌地图
- angular - 嵌套多维数组角度模型
- bash - Bash 脚本:错误,文件意外结束
- spring - 自定义 Spring Zuul 动态路径
- git - 如何将 repo 的一个分支 fork 到一个新的存储库中?