Tkinter按钮在不应该扩展时

时间:2019-07-04 06:44:29

标签: python tkinter

我一直在使用Tkinter进行python文本冒险,并且设置了按钮来处理事件文档中XML文档中的每个动作,我知道每次需要时循环都会运行从我放入的打印语句中删除。但是只有一个按钮出现,当它应该与其他按钮共享时,它将填充整个框架。也许我只是不记得如何使用Tkinter

我尝试pack_propegate(0)无效,甚至尝试放弃pack()代替grid(),这给了我一些我不想要的非常奇怪的结果。

这是游戏运行时我的屏幕外观

What I have

What Should be happening

这是该类的代码,是的,那里是tkinter的导入,是的,CreateActions方法的确如我对打印循环返回到控制台的注释所示运行。缩进的方法就是堆栈溢出插入的方式。

class CommandManager:
    def __init__(self, parent):
        self.Buttons = []
        self.Container = Frame(parent, bg=backgroundColor, highlightthickness=borderSize, highlightbackground=borderColor, height=parent.winfo_screenheight() * .1)
        self.Container.pack_propagate(0)
        self.Container.pack(side=BOTTOM, fill=X)

    def CreateActions(self, actions):

        for action in actions:
            print(action.text)
        # The above loop prints in order
        # test1
        # test2
        # test3
        # test4

        # Action Button 1 is the only button that appears on the screen as seen in the image
        actionButton1 = Button(self.Container, text=actions[0].text, bg=backgroundColor, fg=borderColor, padx=50, pady=50, font='System 32', width=int(round(self.Container.winfo_width() * .2)))
        actionButton1.pack_propagate(1)
        actionButton1.pack(side=LEFT, expand=False)
        actionButton2 = Button(self.Container, text=actions[1].text, bg=backgroundColor, fg=borderColor, padx=50, pady=50, font='System 32', width=int(round(self.Container.winfo_width() * .2)))
        actionButton2.pack(side=LEFT, expand=False)
        actionButton3 = Button(self.Container, text=actions[2].text, bg=backgroundColor, fg=borderColor, padx=50, pady=50, font='System 32', width=int(round(self.Container.winfo_width() * .2)))
        actionButton3.pack(side=LEFT, expand=False)
        actionButton4 = Button(self.Container, text=actions[3].text, bg=backgroundColor, fg=borderColor, padx=50, pady=50, font='System 32', width=int(round(self.Container.winfo_width() * .2)))
        actionButton4.pack(side=LEFT, expand=False)

        '''for action in actions:
            actionButton = Button(self.Container, text=action.text, bg=DEBUG_BGCOLOR, fg=DEBUG_FGCOLOR, padx=50, pady=50, font='System 32', width=int(round(self.Container.winfo_width() * .2)))
            actionButton.pack(side=LEFT, expand=False)
            self.Buttons.append(actionButton)'''

0 个答案:

没有答案