简体   繁体   English

python ttk treeview问题

[英]python ttk treeview issues

I will be honest here and say that I'm playing with the treeviews and ttk without really understand how it works. 我会诚实地说,我正在玩树视图和ttk而不知道它是如何工作的。 Nevertheless, I'm getting some issues and after Googling for it I can't find a proper way to fix it. 然而,我遇到了一些问题,谷歌搜索后,我找不到合适的方法来解决它。 I use treeviews as listbox, since ttk doesn't have a listbox element. 我使用treeviews作为列表框,因为ttk没有listbox元素。

  • 1: Issue 1: somehow I got an extra column all the time, why? 1:问题1:不知怎的,我总是得到一个额外的专栏,为什么?

     chat = ttk.Treeview(height="26", columns=("Nick","Mensaje","Hora"), selectmode="extended") chat.heading('#0', text='Nick', anchor=W) chat.heading('#1', text='Mensaje', anchor=W) chat.heading('#2', text='Hora', anchor=W) chat.column('#0', stretch=NO, minwidth=0, width=100) chat.column('#1', stretch=NO, minwidth=0, width=510) chat.column('#2', stretch=NO, minwidth=0, width=100) chat.place(bordermode=OUTSIDE, x=5, y=45) 

But that adds an extra column at the end so i had to add to fix it: 但是在最后添加了一个额外的列,所以我不得不添加来修复它:

chat.column('#3', stretch=NO, minwidth=0, width=0)
  • Issue 2: While I'm trying to insert items to the treeview , I realized I can't find a way to say where the info should go. 问题2:当我试图将项目插入treeview ,我意识到我找不到一种方法来说明信息的去向。 For example I want a variable to fill column1 but another variable to fill column2 . 例如,我想要一个变量来填充column1而另一个变量来填充column2 As far as I could go was: 据我所知,是:

     chat.insert('', "end", '', text=message) 

But that would only add the message on the column0 . 但这只会在column0上添加消息。 How do i make it saves it on column1 while another var is saved on column0 ? 如何将它保存在column1而另一个var保存在column0

  • Issue 3: Is this really the best (easier, actually) way to display a listbox with ttk? 问题3:这真的是用ttk显示列表框的最佳(更简单,实际)方式吗?

Thank you for your answers. 谢谢您的回答。

Edit: i was tring to do something like this: http://pdqi.com/w/Download/BLT/treeview1.gif or http://zoomq.qiniudn.com/ZQScrapBook/ZqFLOSS/data/20100928164510/multicolumn_treeview_plastiktheme.png 编辑:我想做这样的事情: http ://pdqi.com/w/Download/BLT/treeview1.gifhttp://zoomq.qiniudn.com/ZQScrapBook/ZqFLOSS/data/20100928164510/multicolumn_treeview_plastiktheme.png

For issue 1 : I suggest you to rewrite your code: 对于问题1 :我建议你重写你的代码:

chat = ttk.Treeview(height="26", columns=("Mensaje", "Hora"))

chat.heading('#0', text='Nick', anchor=W)
chat.heading('Mensaje', text='Mensaje', anchor=W)
chat.heading('Hora', text='Hora', anchor=W)

chat.column('#0', stretch=NO, minwidth=0, width=100)
chat.column('Mensaje', stretch=NO, minwidth=0, width=510)
chat.column('Hora', stretch=NO, minwidth=0, width=100)

For issue 2 : Use 对于问题2 :使用

chat.insert('', 'end', 'iid_1')
chat.set('iid_1', 'Hora', 'your value')

For issue 3 : There is not presently a listbox in ttk, but you can use Listboxes from the classic Tk widgets. 对于问题3 :目前ttk中没有列表框,但您可以使用经典Tk小部件中的列表框。

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

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