943,993 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 3231
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
May 29th, 2007
0

Text widget puzzles.

Expand Post »
G'day,

Thanks Mr. Vegaseat, Jeff, Ene, Mawe for all of your great help so far...I'm slowly (very slowly!) getting used to Tkinter.

But I'm again puzzled by how Tkinter does things. Some examples of code at the beginning say "from Tkinter import *" and some say "import Tkinter as tk" and I've even seen "from Tkinter"...nothing else?

Although this isn't the main reason I'm posting which is the following: How does one code a vertical scrolling Text Widget using the "place" positioning in the example below...

Python Syntax (Toggle Plain Text)
  1. # The following code is not a game, it is configured just to test a GUI concept.
  2. num=10
  3. running = True
  4. run=""
  5. while running:
  6. guess=int(raw_input('Enter a number between one and ten : '))
  7. if guess!=num:
  8. print " Number 1"
  9. print
  10. print " Number 2"
  11. print
  12. print " Number 3"
  13. print
  14. print " Number 4"
  15. print
  16. print " Number 5"
  17. print
  18. print " Clue No.1"
  19. print
  20. print " Clue No.2"
  21. print
  22. print " Clue No.3"
  23. print
  24. print " Clue No.4"
  25. print
  26. print " Clue No.5"
  27. print "---------------------------------------------------------------------------"
  28. if guess==num:
  29. print " EXCELLENT!!!!!"
  30. break


When asked to enter a number DO NOT put the number ten in the entry zone until you're ready to exit. The reason for this is to give you an idea of how the game I'm working on looks and how each "frame" is seperated. Which reminds me how do you get the same results as print "--------------" in a verical scrolling Text Widget using place???

I wouldn't post if I could find anything even close to what I need, but again there is zero on the web about this.

Looking forward to your replies with the keenest eyes imaginable .

fredzik.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
fredzik is offline Offline
55 posts
since Feb 2007
May 29th, 2007
0

Re: Text widget puzzles.

Quote ...
But I'm again puzzled by how Tkinter does things. Some examples of code at the beginning say "from Tkinter import *" and some say "import Tkinter as tk" and I've even seen "from Tkinter"...nothing else?
Let's see how you e.g. call an Entry with these (from Tkinter alone won't work, I guess you mean import Tkinter):

1. from Tkinter import * -> entry = Entry()
2. import Tkinter as tk -> entry = tk.Entry()
3. import Tkinter -> entry = Tkinter.Entry()

So, version 2 is just a shortcut for version 3.
With version 1 you pollute your namespace. Think of what happens if you import another module, let's call it Blinker, which also has a class called "Entry".
Python Syntax (Toggle Plain Text)
  1. from Tkinter import *
  2. from Blinker import *
  3. ...
  4. e = Entry()
Is this now the Entry from Tkinter or Blinker? You are confused, Python is confused.

Conclusion: NEVER use from ... import *!
Reputation Points: 19
Solved Threads: 58
Junior Poster
mawe is offline Offline
133 posts
since Sep 2005
May 29th, 2007
0

Re: Text widget puzzles.

G'day Mawe,

You must be in Oz for you to answer my email so quickly. Good to hear from you. We Aussies should stick together and see if we can beat these Americans at there own game i.e. computing (only kidding).

Anyways, yes it is confusing isn't it, as I don't even know which one of these three examples I should start my above code with...have been experimenting with all three and exception after exception is about all I've gotten so far...

Also the way the code above is configured is as rare as hens teeth to find i.e. "a vertical scrolling Text Widget using place" is completely unknown in the annals of Tkinter internet sites and I only have a vague idea of how I should tackle it...

Thanks for your help Mawe.

fredzik.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
fredzik is offline Offline
55 posts
since Feb 2007
Jun 22nd, 2007
0

Re: Text widget puzzles.

G'day,

Came across this explanation which goes some way towards clearing up the confusion about 'import Tkinter as tk', 'import Tkinter' and 'from Tkinter import *'...hope you find it as helpful as I did.

http://mail.python.org/pipermail/pyt...ne/325166.html

Not confused...anymore.

fredzik.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
fredzik is offline Offline
55 posts
since Feb 2007
Jun 22nd, 2007
0

Re: Text widget puzzles.

Quote ...
how do you get the same results as print "--------------" in a verical scrolling Text Widget using place???
Hi, im not sure, whether you are asking for proper indentation of output text/string into vertical scrolling text widget OR place() function's usage.

Well, to get to know about usage of place() function, you can simply type the following in your IDE.

Python Syntax (Toggle Plain Text)
  1. from Tkinter import Entry
  2. Entry().place.__doc__

Note: Python built-in functions are documented. This gives you a brief description of a function. You can access the same its __doc__ attribute.

Quote ...
Python Syntax (Toggle Plain Text)
  1. print " Clue No.5"
Or if you are asking for indenting the text/string you can use
ljust(int)
rjust(int)
functions of the string object.

If you were expecting something different please throw it properly.

Hope this helps.

kath.
Last edited by katharnakh; Jun 22nd, 2007 at 7:31 am.
Reputation Points: 19
Solved Threads: 34
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006
Jun 22nd, 2007
0

Re: Text widget puzzles.

G'day again Katharnakh,

I've never tried "from Tkinter import Entry" before, and...why is this typing coming out green??? All I did was copy and paste "from Tkinter import Entry" from your post and now it's all coming out green...must be the revenge of the green things!!!.

Anyways, I'm not going to double post...where was I, Oh yes, the "Entry" import I've never tried it before, it looks interesting...

The question of the place() function is not workable for the purposes I have in mind...the game seems to only want to work in the Python shell (the one with the blue characters on a white background) and is not transferrable, as is, to any GUI, which is a shame because I'd like some colours to add to it, to liven it up. Somehow I have to strip down the Python shell to accommodate only my game which is a big ask, and have had some limited success so far with it. BTW, does anyone know how to colourize the blue characters in the Python shell?

Thanks again Katharnakh.

Green fredzik. (I think I should stop copying and pasting from the same page, it confuses the Message box)...
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
fredzik is offline Offline
55 posts
since Feb 2007
Jun 22nd, 2007
0

Re: Text widget puzzles.

I don't know what editor or IDE you are using for writing your code. Colour highlighting is generally a function of the IDE and can be customized.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Jun 23rd, 2007
0

Re: Text widget puzzles.

Hi Mr. Vegaseat,

I only use the Python 2.4 and the "Python Shell" itself. I write code simply by going to "File" then "New Window" and write my code from there.

I've cloned PyShell.py (which resides in Idlelib) and called it PyShell2.py which I've partially stripped down to handle only the game. I may have to download Python 2.3 or 2.5 and strip down it's PyShell as I'm finding that the PyShell2.py only loads sometimes, possibly because Python itself sees two "Python Shells" and can't decide which one it should use (it just freezes).

When I say I've only had "some limited success" I do mean LIMITED as the only functions that I've gotten rid of so far are all the characters down to and including "IDLE 1.1" so that when one views the Python Shell itself all one sees is the ">>>" and this is at the very top in the upper left hand corner which kinda looks strange when one is used to the usual Python Shell look.

The whereabouts of the colour/color coding is puzzling as I've ventured into "lib-tk" then "Tkinter" and the coding for colourization is not there unless it has some other name. The "Interactive Interpreter" hasn't got it and I'm therefore puzzled as to where it's hiding. Don't get me wrong I like the blue on white look but the commercial market loves things with colour etc, also some of the "clues" in the game will be more outstanding if there were other colours added to them.

Many thanks.

fredzik.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
fredzik is offline Offline
55 posts
since Feb 2007
Jun 23rd, 2007
0

Re: Text widget puzzles.

If you have a Windows OS, you can use this ...
Python Syntax (Toggle Plain Text)
  1. # change color in the python.exe console display (Windows)
  2. # color is a two digit hexadecimal number
  3. # the first digit is the background
  4. # the second digit is the foreground (text)
  5. # 0=black 1=blue 2=green ... to E=yellow F=white
  6.  
  7. import os
  8. os.system("color F2") # green(2) text on white(F) background
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Jun 23rd, 2007
0

Re: Text widget puzzles.

Learned something! Thanks, vega.

Fredzic: have you discovered the online Tkinter manual yet? It's a real life-saver:

http://infohost.nmt.edu/tcc/help/pubs/tkinter/
http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf (pdf)

It explains how to use and configure a Text widget, an Entry widget, and the place() method.

Jeff
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: parsing xml
Next Thread in Python Forum Timeline: PyQt and Qt Designer: KActionSelector





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC