十五、列表元素的设定方法
1. 列表元素的书写方法
list = ['python', 'java', 'c++', 'php', 'html']
sg.Listbox(list)
sg.LB(list)
2. 按键元素的设定方法
sg.LB(list, size=(None, None))
import PySimpleGUI as sg
list = ['python', 'java', 'c++', 'php', 'html']
layout = [
[sg.LB(list,
default_values=None,
key='-LB',
select_mode=None,
enable_events=False,
bind_return_key=False,
size=(30, 6),
disabled=False,
auto_size_text=None,
font=None,
no_scrollbar=False,
background_color=None,
text_color=None,
pad=None,
tooltip=None,
right_click_menu=None,
visible=True
)]
],
window = sg.Window('Python GUI', layout)
while True:
event, values = window.read()
print(event)
if event == None:
break
window.close()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
十六、列表元素的更新方法
1. 列表元素的更新方法
window[key].update()
window[key].Update()
2. 参数
values = None
disabled = None
set_to_index = None
scroll_to_index = None
select_mode = None
visible = None
十七、在窗口上调用字典里面的键和值
import PySimpleGUI as sg
dict = {'杨幂':'python', '赵丽颖':'java', '刘诗诗':'php', '郭敬明':'html'}
list = []
for i in dict:
list.append(i)
layout = [
[sg.LB(list, key='-LB-', size=(30,6), enable_events=True)],
[sg.T('语言'), sg.In(key='-YY-',size=(25))]
]
window = sg.Window('Python GUI', layout)
while True:
event, values = window.read()
print(event)
if event == None:
break
if event == '-LB-':
window['-YY-'].update(dict[values['-LB-'][0]])
window.close()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
十八、下拉菜单的设定方法
sg.Combo()
sg.InputCombo()
sg.DropDown()
sg.Drop()
- Combo 和 Listbox 最大的区别在于,可以输入,但是不能多选。Listbox 取得的值是存放在类别里面,但是 Combo 取得的值是对象本身。
import PySimpleGUI as sg
list = ['python', 'java', 'c++', 'php', 'html']
layout = [
[sg.Drop(list,
default_value=None,
key='-LB',
size=(30, 6),
auto_size_text=None,
background_color=None,
text_color=None,
enable_events=False,
disabled=False,
pad=None,
tooltip=None,
readonly=False,
font=None,
visible=True
)]
],
window = sg.Window('Python GUI', layout)
while True:
event, values = window.read()
print(event)
if event == None:
break
window.close()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
十九、下拉菜单的更新方法及小练习
1. 下拉菜单的更新方法
window[key].update()
window[key].Update()
2. 下拉菜单可更新的属性
value=None,
values=None,
set_to_index=None,
disabled=None,
readonly=None,
font=None,
visible=None
import PySimpleGUI as sg
dict = {'杨幂':'python', '赵丽颖':'java', '刘诗诗':'php', '郭敬明':'html'}
list = []
for i in dict:
list.append(i)
layout = [
[sg.Combo(list,key='-LB-', size=(30,6), enable_events=True)],
[sg.T('语言'), sg.In(key='-YY-',size=(25))]
]
window = sg.Window('Python GUI', layout)
while True:
event, values = window.read()
print(event)
if event == None:
break
if event == '-LB-':
window['-YY-'].update(dict[values['-LB-']])
window.close()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22