你怎么用tk在python中做到这一点? [英] How do you do this in python with tk?

查看:73
本文介绍了你怎么用tk在python中做到这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个清单:


info = [[''Ali'',18],

[''Zainab'',16 ],

[''Khalid'',18]]


我希望这个信息显示在这样的tk窗口上:


| - | ------------------------ |

| TK | Blah |

| - | ------------------------ |

|姓名:阿里|

|年龄:18 |

| |

|姓名:Zainab |

|年龄:16 |

| |

|姓名:Khalid |

|年龄:18 |

| -------------- ------------- |


我想知道怎么做?

I have a the list:

info = [[''Ali'',18],
[''Zainab'',16],
[''Khalid'',18]]

I want this info to show on a tk window like this:

|--|------------------------|
|TK|Blah |
|--|------------------------|
|Name: Ali |
|Age: 18 |
| |
|Name: Zainab |
|Age: 16 |
| |
|Name: Khalid |
|Age: 18 |
|---------------------------|

I was wondering how to do this?

推荐答案

2004年10月7日星期四15:31:19 -0700,Ali写道:
On Thu, 07 Oct 2004 15:31:19 -0700, Ali wrote:
我有一个清单:

info = [[''阿里',18],
[''Zainab'',16],
[''Khalid'',18]]

我想要这个在这样的tk窗口上显示的信息:

| - | ------------------------ |
| TK | Blah |
| - | ------------------------ |
|姓名:阿里|
|年龄:18 |
| |
|姓名:Zainab |
|年龄:16 |
| |
|姓名:Khalid |
|年龄:18 |
| -------------------------- - |

我想知道怎么做?
I have a the list:

info = [[''Ali'',18],
[''Zainab'',16],
[''Khalid'',18]]

I want this info to show on a tk window like this:

|--|------------------------|
|TK|Blah |
|--|------------------------|
|Name: Ali |
|Age: 18 |
| |
|Name: Zainab |
|Age: 16 |
| |
|Name: Khalid |
|Age: 18 |
|---------------------------|

I was wondering how to do this?



http://www.pythonware.com/library/tk...ction/grid.htm


您是否在发布之前尝试解决这些问题?



http://www.pythonware.com/library/tk...ction/grid.htm

Do you even try to figure these things out before posting?


您可以创建一个文本小部件并在其中插入文本行。


导入Tkinter

def add_rows(w,标题,行):
行中r的


表示t, v in zip(titles,r):

w.insert(" end","%s:\ t%s \ n"%(t,v))
w.insert(" end"," \ n")

app = Tkinter.Tk()

t = Tkinter .Text(app)

t.pack()

info = [[''Ali'',18],

['' Zainab'',16],

[''Khalid'',18]]

add_rows(t,[" Name"," Age"],info)

app.mainloop()


如果有很多行,您可以使用滚动条小部件滚动

文本小部件。您可以使用Text小部件的tabs =参数来

调整第二列的对齐方式。如果你想使

项目交互式,你可以使用标签和tag_bind来对事物做出反应

就像按下按钮一样。您可以将文本小部件设置为已禁用

让用户不要更改内容。


Jeff


----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.2.6(GNU / Linux)

iD8DBQFBZdTNJd01MZaTXX0RAuZqAJ9hsp8Z9V / SN + uP8NEqofZlDD6O4gCdEdgt

caOM + FJ + imW7c2vSj8Bcg7I =

= nWpO

----- END PGP SIGNATURE -----

You could create a Text widget and insert lines of text in it.

import Tkinter
def add_rows(w, titles, rows):
for r in rows:
for t, v in zip(titles, r):
w.insert("end", "%s:\t%s\n" % (t, v))
w.insert("end", "\n")

app = Tkinter.Tk()
t = Tkinter.Text(app)
t.pack()
info = [[''Ali'',18],
[''Zainab'',16],
[''Khalid'',18]]
add_rows(t, ["Name", "Age"], info)
app.mainloop()

If there are many lines, you can use a scrollbar widget to scroll the
text widget. You can use the tabs= argument of the Text widget to
adjust the alignment of the second column. If you want to make the
items "interactive", you can use tags and tag_bind to react to things
like button presses. You can set the text widget to be "disabled" to
keep the user from changing the contents.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBZdTNJd01MZaTXX0RAuZqAJ9hsp8Z9V/SN+uP8NEqofZlDD6O4gCdEdgt
caOM+FJ+imW7c2vSj8Bcg7I=
=nWpO
-----END PGP SIGNATURE-----


Jeremy Bowers< je ** @ jerf.org>在消息新闻中写道:< pa **************************** @ jerf.org> ...
Jeremy Bowers <je**@jerf.org> wrote in message news:<pa****************************@jerf.org>...
2004年10月7日星期四15:31:19 -0700,阿里写道:
On Thu, 07 Oct 2004 15:31:19 -0700, Ali wrote:
我有一个清单:

info = [[' '阿里',18],
[''Zainab'',16],
[''Khalid'',18]]

我希望这些信息能够显示出来在这样的tk窗口上:

| - | ------------------------ |
| TK | Blah |
| - | ------------------------ |
|姓名:阿里|
|年龄:18 |
| |
|姓名:Zainab |
|年龄:16 |
| |
|姓名:Khalid |
|年龄:18 |
| -------------------------- - |

我想知道怎么做?
I have a the list:

info = [[''Ali'',18],
[''Zainab'',16],
[''Khalid'',18]]

I want this info to show on a tk window like this:

|--|------------------------|
|TK|Blah |
|--|------------------------|
|Name: Ali |
|Age: 18 |
| |
|Name: Zainab |
|Age: 16 |
| |
|Name: Khalid |
|Age: 18 |
|---------------------------|

I was wondering how to do this?



http://www.pythonware.com/library/tk...ction/grid.htm

你甚至试着在张贴前弄清楚这些事情吗?



http://www.pythonware.com/library/tk...ction/grid.htm

Do you even try to figure these things out before posting?




是的。



Yes.


这篇关于你怎么用tk在python中做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆