| | |
Text widget puzzles.
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
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...
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.
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)
# The following code is not a game, it is configured just to test a GUI concept. num=10 running = True run="" while running: guess=int(raw_input('Enter a number between one and ten : ')) if guess!=num: print " Number 1" print " Number 2" print " Number 3" print " Number 4" print " Number 5" print " Clue No.1" print " Clue No.2" print " Clue No.3" print " Clue No.4" print " Clue No.5" print "---------------------------------------------------------------------------" if guess==num: print " EXCELLENT!!!!!" 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
Looking forward to your replies with the keenest eyes imaginable

.fredzik.
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
•
•
•
•
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?
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)
from Tkinter import * from Blinker import * ... e = Entry()
Conclusion: NEVER use from ... import *!
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
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.
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.
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
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.
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.
•
•
•
•
how do you get the same results as print "--------------" in a verical scrolling Text Widget using place???
Well, to get to know about usage of place() function, you can simply type the following in your IDE.
Python Syntax (Toggle Plain Text)
from Tkinter import Entry 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.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.
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
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)...
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)...
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
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.
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.
If you have a Windows OS, you can use this ...
Python Syntax (Toggle Plain Text)
# change color in the python.exe console display (Windows) # color is a two digit hexadecimal number # the first digit is the background # the second digit is the foreground (text) # 0=black 1=blue 2=green ... to E=yellow F=white import os os.system("color F2") # green(2) text on white(F) background
May 'the Google' be with you!
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
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
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
![]() |
Other Threads in the Python Forum
- Previous Thread: parsing xml
- Next Thread: PyQt and Qt Designer: KActionSelector
Views: 2765 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Python
anti array avogadro beginner builtin clear client code color count csv curved def dictionary dynamic enter examples excel file float format frange ftp function gui heads homework import input java lapse line lines linux list lists loop microcontroller mouse multiple mysqldb mysqlquery newb number numbers output parsing path port prime program programming projects py2exe pygame pygtk pyopengl pyqt python random raw_input recursion recursive redirect script scrolledtext singleton software sqlite ssh stderr string strings subprocess sum syntax table terminal text thread threading time tkinter tlapse tooltip tuple tutorial twoup ubuntu unicode unix urllib urllib2 variable web-scrape wikipedia windows word wx.wizard wxpython






