简体   繁体   English

我一辈子都无法扩展这个 ttk / tkinter 分隔符

[英]I can't for the life of me get this ttk / tkinter separator to expand

I have to write a program for some coursework I'm doing, and I chose to do an A-Level revision game to help others.我必须为我正在做的一些课程作业编写一个程序,我选择做一个 A-Level 复习游戏来帮助其他人。 I'm trying to get use a ttk separator to split up the area of the window where the game part occurs, and the area of the window where the question sits.我正在尝试使用 ttk 分隔符来分割出现游戏部分的窗口区域和问题所在的窗口区域。 My window is split up into 3 frames;我的窗口被分成 3 个框架; one with 4 labels in, one with 4 buttons in and one with a ttk.Separator widget and a label.一个带有 4 个标签,一个带有 4 个按钮,一个带有 ttk.Separator 小部件和一个标签。 I cannot get the separator however to span the whole window.但是我无法让分隔符跨越整个窗口。

I've been looking around and testing things, but nothing seems to work.我一直在环顾四周并进行测试,但似乎没有任何效果。 I've looked at these two previous posts in terms of on this website:我在这个网站上看过这两个以前的帖子:

ttk.Separator set the length/width ttk.Separator 设置长/宽
A Label in a Frame in a window won't stretch, why? 窗口中框架中的标签不会拉伸,为什么?

but neither of these solutions seemed to fix my problem, and I'm now out of ideas.但这些解决方案似乎都没有解决我的问题,我现在没有想法了。 Any help would be greatly appreciated.任何帮助将不胜感激。

main_revision_game_question_frame = Frame(parent_window, bg='#c2f0f0')
main_revision_game_question_frame.pack()
main_revision_game_question_frame.grid_propagate(1)
main_revision_game_question_frame.config(width=screen_width, height=40)

separator = ttk.Separator(main_revision_game_question_frame, orient=HORIZONTAL)
separator.grid(column=0, row=0, sticky='ew')

question_label = Label(main_revision_game_question_frame,
                               text='     Placeholder text for a question goes here!    
                             \n######################################################',
                               bg='#c2f0f0', fg='#ff2824', font='"Open Sans" 26 bold')
question_label.grid(column=0, row=1, sticky='ew')

main_revision_game_question_frame.grid_columnconfigure(0,weight=1)
main_revision_game_question_frame.grid_rowconfigure(0, weight=1)

This is the code I've ended up with upon trying to combine a few solutions, and this is how it looks:这是我在尝试组合一些解决方案时最终得到的代码,它是这样的:

在此处输入图片说明

You can see the separator is there, but it does not stretch across the frame.您可以看到分隔符在那里,但它没有跨过框架。 Thank you for reading.感谢您的阅读。

The separator is expanding to fill the frame, but the frame hasn't been configured to fill the space it has been given.分隔符正在扩展以填充框架,但框架尚未配置为填充其给定的空间。

You need to expand the frame.您需要扩展框架。 One way to do that is to use the fill option of pack :一种方法是使用packfill选项:

main_revision_game_question_frame.pack(fill="x")

Try to use尝试使用

main_revision_game_question_frame.pack(fill="both")

so the frame fills the whole space it is given所以框架填满了它给定的整个空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM