【发布时间】:2021-09-25 03:38:38
【问题描述】:
我有一个 ttk Treeview 的以下代码:
listbox = ttk.Treeview(
tab_player,
columns=('Player', 'Rating', 'Price'),
selectmode="extended",
show="headings"
)
listbox.heading('#1', text='Player', anchor=tk.CENTER)
listbox.heading('#2', text='Rating', anchor=tk.CENTER)
listbox.heading('#3', text='Price', anchor=tk.CENTER)
listbox.column('#1', stretch=tk.YES, minwidth=50, width=80)
listbox.column('#2', stretch=tk.YES, minwidth=50, width=20)
listbox.column('#3', stretch=tk.YES, minwidth=50, width=30)
listbox.grid(row=5, column=5, rowspan=7, sticky=W)
我的插入函数如下:
def insertitem():
GUI.listbox.insert('', 'end', values = (GUI.listbox_content.get(),
GUI.listboxr_content.get(),
GUI.listbox_content_price.get()))
稍后我想遍历 Treeview 并从每行的每一列中获取值,以使用这些值在带有 selenium 的网站上填写某些表单。
示例:
str_libo_p = GUI.listbox.column.__getattribute__('Player')
str_libo_r = GUI.listbox.column.__getattribute__('Rating')
str_libo_price = GUI.listbox.column.__getattribute__('Price')
#### some uninteresting code in between
for i, r, p in zip(str_libo_p, str_libo_r, str_libo_price):
# values will be used to fill specific entry fields on a website.
# just as an example to let you know what I am using it for:
text_playername = init_webdriver.wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
(
#####
),
)
)
)
text_playername.click()
text_playername.send_keys(i)
# same will be done for text_player_rating.send_keys(r) and
# text_player_price.send_keys(p) with different XPATHs
从文档中我不明白我应该在这里调用哪个函数来获得一个值作为回报。
GUI.listbox.column.__getattribute__('Price') 没有给我我需要的结果。
【问题讨论】: