【问题标题】:grid_columnconfigure() Not Working Inside my Framegrid_columnconfigure() 在我的框架内不起作用
【发布时间】:2021-08-23 06:21:44
【问题描述】:

这是我的代码

from tkinter import *

root = Tk()

myframe = Frame(root, bg="red")
myframe.pack()

btn1 = Button(myframe, text="Button 1", font="Comicsans 15 bold")
btn1.grid(row=0, column=0)

btn2 = Button(myframe, text="Button 2", font="Comicsans 15 bold")
btn2.grid(row=0, column=1)

root.grid_columnconfigure((0, 1), weight=1)

root.mainloop()

如何让grid_columnconfigure() 工作?

【问题讨论】:

  • root.grid_columnconfigure更改为myframe.grid_columnconfigure

标签: python user-interface tkinter interface


【解决方案1】:

您在root 上调用它,但root 中的小部件正在使用pack。如果您预计它会影响按钮,您需要在myframe 上调用它:

myframe.grid_columnconfigure((0,1), weight=1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    相关资源
    最近更新 更多