Text widget puzzles.

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2007
Posts: 55
Reputation: fredzik is an unknown quantity at this point 
Solved Threads: 4
fredzik fredzik is offline Offline
Junior Poster in Training

Text widget puzzles.

 
0
  #1
May 29th, 2007
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...

  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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: Text widget puzzles.

 
0
  #2
May 29th, 2007
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".
  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 *!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 55
Reputation: fredzik is an unknown quantity at this point 
Solved Threads: 4
fredzik fredzik is offline Offline
Junior Poster in Training

Re: Text widget puzzles.

 
0
  #3
May 29th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 55
Reputation: fredzik is an unknown quantity at this point 
Solved Threads: 4
fredzik fredzik is offline Offline
Junior Poster in Training

Re: Text widget puzzles.

 
0
  #4
Jun 22nd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Text widget puzzles.

 
0
  #5
Jun 22nd, 2007
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.

  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.

  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 55
Reputation: fredzik is an unknown quantity at this point 
Solved Threads: 4
fredzik fredzik is offline Offline
Junior Poster in Training

Re: Text widget puzzles.

 
0
  #6
Jun 22nd, 2007
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)...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,135
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 946
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Text widget puzzles.

 
0
  #7
Jun 22nd, 2007
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.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 55
Reputation: fredzik is an unknown quantity at this point 
Solved Threads: 4
fredzik fredzik is offline Offline
Junior Poster in Training

Re: Text widget puzzles.

 
0
  #8
Jun 23rd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,135
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 946
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Text widget puzzles.

 
0
  #9
Jun 23rd, 2007
If you have a Windows OS, you can use this ...
  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
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Text widget puzzles.

 
0
  #10
Jun 23rd, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum


Views: 2765 | Replies: 10
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC