473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How do you do this in python with tk?

Ali
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?
Jul 18 '05 #1
16 1432
On Thu, 07 Oct 2004 15:31:19 -0700, Ali wrote:
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

Do you even try to figure these things out before posting?
Jul 18 '05 #2
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-----

Jul 18 '05 #3
Ali
Jeremy Bowers <je**@jerf.org> wrote in message news:<pa****************************@jerf.org>...
On Thu, 07 Oct 2004 15:31:19 -0700, Ali wrote:
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

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


Yes.
Jul 18 '05 #4
Ali
Jeff Epler <je****@unpythonic.net> wrote in message news:<ma**************************************@pyt hon.org>...
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

--


I will try out your code. Thank you for helping.
Jul 18 '05 #5
Ali
> >You can set the text widget to be "disabled" to
keep the user from changing the contents.


How? I tryed putting diabled in there and disabled=yes and
disabled='yes'. None of them worked :(
Jul 18 '05 #6
al**********@hotmail.com (Ali) wrote in message news:<8f*************************@posting.google.c om>...
You can set the text widget to be "disabled" to
keep the user from changing the contents.


How? I tryed putting diabled in there and disabled=yes and
disabled='yes'. None of them worked :(


Try state="disabled"

Michael
Jul 18 '05 #7
Ali
kl*******@web.de (klappnase) wrote in message news:<a7*************************@posting.google.c om>...
al**********@hotmail.com (Ali) wrote in message news:<8f*************************@posting.google.c om>...
>You can set the text widget to be "disabled" to
> keep the user from changing the contents.


How? I tryed putting diabled in there and disabled=yes and
disabled='yes'. None of them worked :(


Try state="disabled"

Michael


I tryed that and it stoped showing the text I want it to show :(
Jul 18 '05 #8
Ali wrote:
kl*******@web.de (klappnase) wrote in message news:<a7*************************@posting.google.c om>...
al**********@hotmail.com (Ali) wrote in message news:<8f*************************@posting.google.c om>...
>You can set the text widget to be "disabled" to
>keep the user from changing the contents.

How? I tryed putting diabled in there and disabled=yes and
disabled='yes'. None of them worked :(


Try state="disabled"

Michael

I tryed that and it stoped showing the text I want it to show :(


Setting state='disabled' does not only prevent the user from editing the text,
but also prevents *you* from modifying the text via the insert or delete
methods. So whenever you want to insert or delete lines in the text, you must
configure its state to 'normal' before, do the modification, then set back its
state to 'disabled'

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Jul 18 '05 #9
Ali
>
Setting state='disabled' does not only prevent the user from editing the text,
but also prevents *you* from modifying the text via the insert or delete
methods. So whenever you want to insert or delete lines in the text, you must
configure its state to 'normal' before, do the modification, then set back its
state to 'disabled'

HTH


OK so I tryed:

import Tkinter
def add_rows(w, titles, rows):
t.state = 'normal'
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()

it still wont show the text I want it to.
Jul 18 '05 #10
Hello Ali,
import Tkinter
def add_rows(w, titles, rows):
t.state = 'normal' w.state = 'normal' 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()


HTH.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys
Jul 18 '05 #11
Ali wrote:
Setting state='disabled' does not only prevent the user from editing the text,
but also prevents *you* from modifying the text via the insert or delete
methods. So whenever you want to insert or delete lines in the text, you must
configure its state to 'normal' before, do the modification, then set back its
state to 'disabled'

HTH

OK so I tryed:

import Tkinter
def add_rows(w, titles, rows):
t.state = 'normal'


tk options are not exposed as widget attributes, but via the configure method or
dictionary-style indexing. So this should be:

w.configure(state='normal')

or:

w['state'] = 'normal'

What you did only creates a new attribute named "state" for the widget, which
has no meaning at all at tk level.

[snip]

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Jul 18 '05 #12
Ali
Eric Brunel <er*********@despammed.com> wrote in message news:<41**********************@news.wanadoo.fr>...
Ali wrote:
Setting state='disabled' does not only prevent the user from editing the text,
but also prevents *you* from modifying the text via the insert or delete
methods. So whenever you want to insert or delete lines in the text, you must
configure its state to 'normal' before, do the modification, then set back its
state to 'disabled'

HTH

OK so I tryed:

import Tkinter
def add_rows(w, titles, rows):
t.state = 'normal'


tk options are not exposed as widget attributes, but via the configure method or
dictionary-style indexing. So this should be:

w.configure(state='normal')

or:

w['state'] = 'normal'

What you did only creates a new attribute named "state" for the widget, which
has no meaning at all at tk level.

[snip]

HTH


well I tryed this:

import Tkinter
def add_rows(w, titles, rows):
t.configure(state = 'normal')
w.configure(state = 'normal')
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()

Well... it shows the window, it doesnt show text, it still lets me type in stuff :(
What is wrong now?
Jul 18 '05 #13
Ali wrote:
[snip]
well I tryed this:

import Tkinter
def add_rows(w, titles, rows):
t.configure(state = 'normal')
REMOVE THAT LINE! Since you use t as a local variable afterwards, this will make
the whole script fail. BTW, this means this isn't the code you actually used,
since it doesn't display any window at all.
w.configure(state = 'normal')
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()

Well... it shows the window, it doesnt show text, it still lets me type in stuff :(
What is wrong now?


You never set the text state to disabled, so no wonder you can still type text in...
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Jul 18 '05 #14
Ali
Eric Brunel <er*********@despammed.com> wrote in message news:<41**********************@news.wanadoo.fr>...
Ali wrote:
[snip]
well I tryed this:

import Tkinter
def add_rows(w, titles, rows):
t.configure(state = 'normal')


REMOVE THAT LINE! Since you use t as a local variable afterwards, this will make
the whole script fail. BTW, this means this isn't the code you actually used,
since it doesn't display any window at all.
w.configure(state = 'normal')
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()

Well... it shows the window, it doesnt show text, it still lets me type in stuff :(
What is wrong now?


You never set the text state to disabled, so no wonder you can still type text in...


ok so I typed:

import Tkinter
def add_rows(w, titles, rows):
w.configure(state = 'normal')
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, state='disabled')
t.pack()
info = [['Ali',18],
['Zainab',16],
['Khalid',18]]
add_rows(t, ["Name", "Age"], info)
app.mainloop()

This now shows the text but, will still let me edit the text in side! :(
Jul 18 '05 #15
"Ali" wrote:
You never set the text state to disabled, so no wonder you can still type text in...


ok so I typed:

import Tkinter
def add_rows(w, titles, rows):
w.configure(state = 'normal')
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, state='disabled')
t.pack()
info = [['Ali',18],
['Zainab',16],
['Khalid',18]]
add_rows(t, ["Name", "Age"], info)
app.mainloop()

This now shows the text but, will still let me edit the text in side! :(


when the state is set to normal, you can insert text into the widget, and
so can the user. when the state is set to disabled, you cannot insert text,
and neither can the user.

now try setting the state to disabled *after* you've inserted the text.

</F>

Jul 18 '05 #16
Ali
Thank you all!! it now works just fine! The following is the final code!

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

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

Thank you all again! :):):)
Jul 18 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olaf Meyer | last post by:
I'm having some problems compiling Python 2.3.3 on HP-UX (B.11.00). I've tried sevral different options for the configure script (e.g. enabling/disabling gcc, aCC) but I always get the same problem...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 259 open ( -5) / 2573 closed (+17) / 2832 total (+12) Bugs : 745 open ( +0) / 4405 closed (+21) / 5150 total (+21) RFE : 150 open...
1
by: Jerald | last post by:
Running python 2.3.4 on valgrind (a tool like purify which checks the use of uninitialized memory, etc), gives a lot of errors. See below. jfj@cluster:~/> python -V Python 2.3.4...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 241 open ( -6) / 2622 closed (+26) / 2863 total (+20) Bugs : 764 open ( +6) / 4453 closed (+38) / 5217 total (+44) RFE : 150 open...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 391 open ( +7) / 3028 closed (+12) / 3419 total (+19) Bugs : 906 open ( -3) / 5519 closed (+19) / 6425 total (+16) RFE : 207 open...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 420 open ( +4) / 3410 closed ( +2) / 3830 total ( +6) Bugs : 915 open (+17) / 6186 closed ( +6) / 7101 total (+23) RFE : 235 open...
11
by: Osiris | last post by:
I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.