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...

# 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
        print " Number 2"
        print
        print " Number 3"
        print
        print " Number 4"
        print
        print " Number 5"
        print
        print "                                                           Clue No.1"
        print
        print "                                                           Clue No.2"
        print
        print "                                                           Clue No.3"
        print
        print "                                                           Clue No.4"
        print
        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:icon_cry: there is zero on the web about this.

Looking forward to your replies with the keenest eyes imaginable:):) :).

fredzik.

Recommended Answers

All 10 Replies

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".

from Tkinter import *
from Blinker import *
...
e = Entry()

Is this now the Entry from Tkinter or Blinker? You are confused, Python is confused.

Conclusion: NEVER use from ... import *!

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:confused:, 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:icon_biggrin:.

fredzik.

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.

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.

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.

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 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.

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.

If you have a Windows OS, you can use this ...

# 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

G'day,

Mr. Vegaseat, how on earth did you know about
this? Whenever I googlized around:icon_eek: all I ever found was
"Python code colouring" and suchlike. I went to many
and they were all about colouring code. In the end I
was thinking "maybe one should venture into the code
colouring part of Python and somehow scavenge there
that code colouring ability and transfer it over to the
ordinary program strings etc and when that program runs
the stings etc will then be coloured "...my brain
sometimes thinks clearly about these types of matters.
Anyways, the code you gave me does a great job
colouring in the command line, and the combinations are
almost endless...

Jeff, I award you my Congressional Medal of Honour for
your ability to save lives...:)

Seriously though guys, you both have been a great help.
Before I started posting in, I tried quite a few of
both of your examples and gained a fair bit of know how
about Python in general. Although I don't use the
"command line" for much these days (I usually only play
my game in the "Python Shell" the shell where when one
runs a program the characters, strings and integers etc
come out in blue colouring on a white background this
is the shell where I needed the colouring changes to be
done in) I play mainly in this shell because nowadays,
for games in general, there's a full screen (the
"Python Shell" is almost a full screen except for the
task bar at the bottom ) to play on, and the command
line itself isn't full screen - other reasons are that
the command line strings etc don't seem to be as
clearly defined and are smaller than the "Python Shell"
strings etc are when programs are run in it (maybe I
need glasses on this one) and as this game relies
fairly heavily on the readabilty of "clues" etc, I
therefore usually use the Python Shell for all my
programs. I open from Python Shell in site packages the
needed program then I open the "xyz.py" and when the
program comes on-screen I hit the "run" button. I only
mention this because I know that others use editors and
suchlike to run their programs from and definitely
won't have the same results with my "programs" that
I've come up with, I only know this because I've tried
other editors. BTW, please use the Python Shell in this
same way for all of my previous examples.

It's funny though, I never thought you could change the
"dos look" in the command line at all, that is, till
now.:)

I humbly thank you both.

A humblized:icon_rolleyes:...fredzik.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.