Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在PySimpleGUI中滚动不适用于下拉选择_Python_Python 3.x_Pysimplegui - Fatal编程技术网

Python 在PySimpleGUI中滚动不适用于下拉选择

Python 在PySimpleGUI中滚动不适用于下拉选择,python,python-3.x,pysimplegui,Python,Python 3.x,Pysimplegui,当我使用键盘进行下拉选择时,滚动不会上下移动,所以我现在无法看到选择了哪一个。如何在上下按下键盘时上下滚动。我的示例代码如下所示: 将PySimpleGUI导入为sg 类GUI(): 定义初始化(自): self.data=[(10)、(20)、(30)、(40)、(50)、(60)、(70)、(80)、(90)、(100)] self.work\u order\u current\u selection\u index=0 def运行(自): 布局=[[sg.Listbox(值=self.da

当我使用键盘进行下拉选择时,滚动不会上下移动,所以我现在无法看到选择了哪一个。如何在上下按下键盘时上下滚动。我的示例代码如下所示:

将PySimpleGUI导入为sg
类GUI():
定义初始化(自):
self.data=[(10)、(20)、(30)、(40)、(50)、(60)、(70)、(80)、(90)、(100)]
self.work\u order\u current\u selection\u index=0
def运行(自):
布局=[[sg.Listbox(值=self.data,大小=(35,3),enable_events=True,key='selected_key')]]
#创建窗口
self.testWindow=sg.Window('Test',返回\键盘\事件=True).布局(布局).Finalize()
self.testWindow.Maximize()
self.testWindow.Element('selected_key').Update(将_设置为_index=0)
#处理“事件”的事件循环
尽管如此:
事件,值=self.testWindow.Read()
如果事件处于('Up:111','16777235'):
if(hasattr(self,'testWindow')):
self.work\u order\u current\u selection\u index=(self.work\u order\u current\u selection\u index-1)%len(self.data)
self.testWindow.Element('selected_key').Update(将_设置为_index=self.work\u order\u current\u selection\u index)
事件中的elif('Down:116','16777237'):
if(hasattr(self,'testWindow')):
self.work\u order\u current\u selection\u index=(self.work\u order\u current\u selection\u index+1)%len(self.data)
self.testWindow.Element('selected_key').Update(将_设置为_index=self.work\u order\u current\u selection\u index)
self.testWindow.Close()
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app=GUI()
app.run()
当应用程序第一次启动时,我只能看到三个下拉列表,

我按了向下箭头键,然后选择一个接一个地往下走

但选择30后,按向下键选择移动到下一个,如40、50。。除了滚动,所以我现在看不到选择了哪一个。 有没有办法在滚动的同时移动选择


查看第四幅图像,此处选择移动到40,但滚动未向下移动。按下up键时也会出现同样的问题。

也许这会让你更接近你想要的东西

将PySimpleGUI导入为sg
类GUI():
定义初始化(自):
self.data=[(10)、(20)、(30)、(40)、(50)、(60)、(70)、(80)、(90)、(100)]
self.work\u order\u current\u selection\u index=0
def运行(自):
布局=[[sg.Listbox(值=self.data,大小=(35,3),enable_events=True,key='selected_key')]]
#创建窗口
self.testWindow=sg.Window('Test',layout,return\u keyboard\u events=True,finalize=True)
#self.testWindow.Maximize()
self.testWindow.Element('selected_key').Update(将_设置为_index=0)
#处理“事件”的事件循环
尽管如此:
事件,值=self.testWindow.Read()
如果事件为无:
打破
如果event.startswith('Up'):
self.work\u order\u current\u selection\u index=(self.work\u order\u current\u selection\u index-1)%len(self.data)
self.testWindow['selected_key'].Update(将_设置为_index=self.work\u order\u current\u selection\u index,滚动至_index=self.work\u order\u current\u selection\u index)
elif event.startswith('Down'):
self.work\u order\u current\u selection\u index=(self.work\u order\u current\u selection\u index+1)%len(self.data)
self.testWindow['selected_key'].Update(将_设置为_index=self.work\u order\u current\u selection\u index,滚动至_index=self.work\u order\u current\u selection\u index)
self.testWindow.Close()
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app=GUI()
app.run()

当我通过单击鼠标然后用键盘上下移动来完成第一次选择时,同样的事情也能很好地工作。我想你已经理解了答案以及你缺少的东西,即滚动到索引参数。我目前看到的代码不需要使用类。它只是意味着在所有的东西前面输入一个额外的“self:-)一个函数将尽我所能工作得很好,但我不知道这段代码的整体适用性。