[英]Automatically add a scroll in Multiline when the number of rows is exceeded
Tell me how to automatically connect scrolling in PySimpleGUI Multiline when the number of lines entered exceeds.告诉我当输入的行数超过时如何在 PySimpleGUI Multiline 中自动连接滚动。 For example, to enable scrolling when there are more than 5 lines例如,当超过 5 行时启用滚动
sg.Multiline(size=(42, 5))
import PySimpleGUI as sg
def begin_window():
layout = [[sg.Multiline(size=(42, 5), autoscroll=True)]]
# Create the Window
window = sg.Window('Title', layout)
# window['-INDEX-'].bind("<Return>", "_Enter")
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == '-CANCEL-': # if user closes window or clicks cancel
break
window.close()
return
if __name__ == '__main__':
begin_window()
Scroll appears immediately, when the field is empty当字段为空时,滚动立即出现
The method is to hack the method set
for the tk.Scrollbar
, and it is only work for the vertical scrollbar for following code.该方法是破解为tk.Scrollbar
set
的方法,它仅适用于以下代码的垂直滚动条。
import PySimpleGUI as sg
def scrollbar_set(self, lo, hi):
if float(lo) <= 0.0 and float(hi) >= 1.0:
self.pack_forget()
elif self.cget("orient") != sg.tk.HORIZONTAL:
self.pack(side=sg.tk.RIGHT, fill=sg.tk.Y)
self.old_set(lo, hi)
sg.tk.Scrollbar.old_set = sg.tk.Scrollbar.set
sg.tk.Scrollbar.set = scrollbar_set
layout = [
[sg.Text('Auto hide scrollbar', size=25)],
[sg.Multiline(size=(20, 5), expand_x=True, expand_y=True, key='-ML-')]]
window = sg.Window('Title', layout, finalize=True)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
window.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.