简体   繁体   English

使用预制用户界面 (pygubu) 时如何在 Tkinter 中扩展滚动条

[英]How to expand a Scrollbar in Tkinter when working with a pre-made user interface (pygubu)

PyGubu is a simple Python program that allows to create UI interfaces with Tkinter widgets. PyGubu 是一个简单的 Python 程序,它允许使用 Tkinter 小部件创建 UI 界面。

So I have created an UI like this one here on the right所以我在右边创建了一个像这样的用户界面

在此处输入图片说明

Now, I want that Scrollbar to be as big as the Text widget.现在,我希望 Scrollbar 和 Text 小部件一样大。

"How can I make the Scrollbar bigger on Tkinter" has been asked many times on StackOverflow. “如何在 Tkinter 上使滚动条变大”已在 StackOverflow 上被多次询问。 In my case, I cannot use the functions pack() or grid() as I am importing an already semi-finished UI就我而言,我无法使用函数 pack() 或 grid() 因为我正在导入一个已经半完成的 UI

The code I use to load the Text and the Scrollbar is as the following:我用来加载文本和滚动条的代码如下:

    self.log = builder.get_object('log')
    self.log_scroll = builder.get_object('log_scroll')
    self.log.config(yscrollcommand=self.log_scroll.set)
    self.log_scroll.config(command=self.log.yview)

Now, I see two possibilities here:现在,我在这里看到两种可能性:


1. Solving from PyGubu 1.从PyGubu解决

The easiest way should be setting some attributes from PyGubu to solve this.最简单的方法应该是从 PyGubu 设置一些属性来解决这个问题。 Yet, PyGubu allows me to change only a minor number of attributes of the Scrollbar, and none of them seems to be relevant然而,PyGubu 只允许我更改 Scrollbar 的少量属性,而且它们似乎都不相关

2. Solving from Python 2. 从 Python 解决

And here I have no idea about what to do.在这里,我不知道该怎么做。 I don't know if I can use pack() and grid() while using a custom-made interface我不知道我是否可以在使用自定义界面的同时使用 pack() 和 grid()

Any help is appreciated任何帮助表示赞赏

While writing the question, I've found a not-so-intuitive answer, still the best one:在写这个问题时,我找到了一个不太直观的答案,但仍然是最好的答案:

在此处输入图片说明

The property "sticky" is the one who can solve the problem. “粘性”属性是可以解决问题的属性。 What is not-so-intuitive is that you can select multiple squares ctrl+click.不那么直观的是您可以选择多个方块 ctrl+click。 If you are used to work with Tkinter, it would probably not surprise you, but in my case (first day with Tkinter) I can just consider myself lucky如果您习惯使用 Tkinter,那可能不会让您感到惊讶,但就我而言(使用 Tkinter 的第一天)我可以认为自己很幸运

When you set the sticky option in Pygubu, even when all three squares are highlighted, it sets NS (North South), which is the expected result.当您在 Pygubu 中设置粘性选项时,即使所有三个方块都突出显示,它也会设置 NS(北南),这是预期的结果。 在此处输入图片说明

The generated code will also just have 'ns', like this:生成的代码也只有“ns”,如下所示:

self.scroll_bar.grid(column='0', row='0', sticky='ns')

Selecting the central/middle square in Pygubu won't affect 'ns'.在 Pygubu 中选择中央/中间方块不会影响“ns”。 It should still give you the expected result when you have the 3 squares highlighted.当您突出显示 3 个方块时,它仍然应该给您预期的结果。

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

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