a1eio 16 Junior Poster

You could display the path your program gets from the user in a Tkinter Label positioned below the buttons?

a1eio 16 Junior Poster

what do you mean when you ask how to make the program show the paths to the selected folder and file.

Do you want to show the file's contents, show an explorer window of the file's location or some sort of tree view of the file?

a1eio 16 Junior Poster

school rules concerning computers suck.
I have never met a schoo technician who is GOOD at his/her job,
They always impose ridiculous restrictions for example at my school you can't even check the time on the windows startbar?? wtf??

In my opinion it provokes students to "mess" with the system just to return some of that 'grief' they so fondly hand out.

a1eio 16 Junior Poster

For more information on threading read this excellent 4 page tutorial:
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/

a1eio 16 Junior Poster
encode = lambda txt: ".".join([str(ord(letter)-96) for letter in txt if ord(letter) in range(97,123)])

decode = lambda txt: "".join([chr(int(char)+96) for char in txt.split(".") if int(char) in range(1, 27)])

Output >>>

>>> encode('this is a message!!!') # anything not lowercase a-z gets silently ignored
'20.8.9.19.9.19.1.13.5.19.19.1.7.5' 

>>> decode('20.8.9.19.9.19.1.13.5.19.19.1.7.5')
'thisisamessage' # spaces and '!' are gone

pseudo:

new_string = ""
for each character in string:
   check the character is lowercase a-z
   covert character to ascii code and minus 96 
   convert the number back into a string and add it onto the end of new_string

return new_string

Hope that helps,
a1eio

a1eio 16 Junior Poster

Google have this thing called the Google App Engine.

Google App Engine lets you run your web applications on Google's infrastructure.
...
Google App Engine applications are implemented using the Python programming language. The runtime environment includes the full Python language and most of the Python standard library.

Link: http://code.google.com/appengine/docs/whatisgoogleappengine.html

a1eio 16 Junior Poster

when you create a socket, you need to bind it with a port, address so other sockets have something to connect to.

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((address, port))
a1eio 16 Junior Poster

try GUI2exe, it's a gui wrapper for py2exe.
http://xoomer.alice.it/infinity77/main/GUI2Exe.html

a1eio 16 Junior Poster

Hmm.. Well strangely enough it works on my machine (XP)
From idle and from cmd.

Not sure what the problem is, but if you need to get the address of a messege sender then just do that in the thread (if it's sockets it will be safe)

a1eio 16 Junior Poster

python has a keyword function in that would be useful in your example.

if password in pass_list1:
    # do something
a1eio 16 Junior Poster

can you post the traceback? and what module's are you using?

a1eio 16 Junior Poster

there must be something else going on. When you make a copy of a list list2 = list1[:] it fills list2 with list1's values, but when you change either list1 or list2, the change isn't mirrored so list1 would stay the same if list2 was changed.

Are you sure your not doing something else incorrect? If you can, post the section of your code were the checker lists are used and changed etc then someone might be able to see if anything else is happening

a1eio 16 Junior Poster

Thanks.
Yea not a problem i'll put it there now.

And I will look up the python code guidlines thing (i have heard of it before to be honest) i'm just lazy hehe.

a1eio 16 Junior Poster
# This is meant to draw Start and Stop buttons and a label
# The Start button should start a loop in which the label
# is configured to change colour and text.
# At each pass through the loop the variable self.stop is checked:
# if True the loop should terminate.
# The Stop button should terminate the loop by setting the
# variable self.stop to True.
# I have two problems:
# 1. the Stop button does not interrupt the loop
# 2. the label only shows its reconfigured state at the end of the loop

# Please, what are my misconceptions about how this works, and what
# do I need to do to make it do what I expected?
# What I am really trying to do is show an animation but have a button
# to enable users to stop it.

from Tkinter import *
import time
from random import choice

COLORS = ['red','green','blue','orange','brown','black','white','purple','violet']

class SGWidget(Frame):
    def __init__(self, parent=None):
        Frame.__init__(self, parent)
        self.top_frame = Frame(bg='green')
        self.top_frame.grid()
        self.top_frame.update_idletasks()
        self.makeToolbar()
        self.label = Label(self.top_frame,
                           text = 'Text',bg='orange')
        self.label.grid()

    def makeToolbar(self):
        self.toolbar_text = ['Start','Stop']
        self.toolbar_length = len(self.toolbar_text)
        self.toolbar_buttons = [None] * self.toolbar_length

        for toolbar_index in range(self.toolbar_length):
            text = self.toolbar_text[toolbar_index]
            bg = 'yellow'
            button_id = Button(self.top_frame, 
                               text=text,
                               background=bg)

            button_id.grid(row=0, column=toolbar_index)
            self.toolbar_buttons[toolbar_index] = button_id

            def toolbar_button_handler(event, self=self, button=toolbar_index):
                return self.service_toolbar(button)
            button_id.bind("<Button-1>", toolbar_button_handler)
                
    def service_toolbar(self, toolbar_index):
        if toolbar_index == 0:
            self.stop = False
            print self.stop
            self.blink()
        if toolbar_index == 1:
            self.stop = True
            print self.stop

    def blink(self):
        if not self.stop:
            print 'looping',self.stop …
a1eio 16 Junior Poster

excellent, happy coding

a1eio 16 Junior Poster

You don't need to get a fileobject though. As solsteel pointed out, the csv module doesn't need a fileobject, it just needs something to iterate through, so if you split the self[filename] string by every newline ('\n') then you will end up with a list of lines which the csv reader module can parse.

Solsteel's example looks perfect.

csv.reader(str(self[filename]).split('\n'))
a1eio 16 Junior Poster

well as far as i can see, whatever resides within self[filename] is clearly not a valid filepath.

There was a sort of hint to what it might contain in the second error.

[IOError] of [Errno 36] File name too long: 'ProjCat,RefNum,ProjTitle,MemberName,ProjDeadline,ProjGrade\nI,0001,"Medical Research in XXX Field,2007","Gary,Susan",20.05.07,80\nR,0023,Grid Computing in today era,"Henry Williams,Tulali Mark",04-May-07,--NA--........'

ProjCat,RefNum,ProjTitle,.... etc etc, that is not a filepath.

the open function needs a filepath string like 'textfile.txt' and you appear to be passing a very very long string of words, comma's etc.

You should read the documentation for the csv module, and i think Zope is confusing things. are you trying to parse a file thats stored somewhere (has a filename .csv etc)? or are you reading the csv data from zope. If it's from zope then i don't think the open() command is what you want.
Open opens a file and returns a fileobject, which csv.reader() then parses, if self[filename] isn't a file then it will not work.

a1eio 16 Junior Poster
def function(*args):
    print type(args)
    print args

function('arg1', 'arg2', 'arg3')

output

<type 'tuple'>
('arg1', 'arg2', 'arg3')

If you need a list: args = list(args)

a1eio 16 Junior Poster

You should definitely use tkinters .after() function, it enters a local event loop which means it doesn't block your program.

def blink(self):
        if not self.stop: # check self.stop is false before proceeding
            print 'looping',self.stop
            self.label.configure(bg=choice(COLORS))
            self.label.update_idletasks()

            self.after(100, self.blink) # after 100 ms, call function self.blink

choice is a function imported from random,
COLORS is a list containing colors, eg: ['green','red','blue'] etc

Hope that helps

a1eio 16 Junior Poster
n = float(2)
m = float(3)
print n/m

Or

n = 2.0
m = 3.0
print n/m

Hope that helps.

a1eio 16 Junior Poster

Well you could just use a Thread object to do the counting for you and then in your main program everytime the user enters a key, you just call a function of the Thread object counting that returns it's current value.

The example below might help.

# counterTest.py, a1eio

import threading

# create a thread object that will do the counting in a separate thread
class counter(threading.Thread):
    def __init__(self, value, increment):
        threading.Thread.__init__(self) # init the thread
        self.value = value # initial value
        self.increment = increment # amount to increment
        self.alive = False # controls the while loop in the run command

    def run(self): # this is the main function that will run in a separate thread
        self.alive = True
        while self.alive:
            self.value += self.increment # do the counting

    def peek(self): # return the current value
        return self.value

    def finish(self): # close the thread, return final value
        self.alive = False # stop the while loop in 'run'
        return self.value # return value

def Main():
    # create separate instances of the counter
    counterA = counter(1, 1) #initial value, increment
    counterB = counter(1, 2) #initial value, increment
    counterC = counter(1, 3) #initial value, increment

    # start each counter
    counterA.start()
    counterB.start()
    counterC.start()

    print "Enter A, B, or C to view counters\nEnter Q to quit"
    while True:
        Input = raw_input("> ").upper() # get input

        if Input == 'A':
            print 'CounterA: ', counterA.peek() # print counterA's value
        elif Input == 'B':
            print 'CounterB: ', counterB.peek() # print counterB's value
        elif Input == 'C':
            print …
vegaseat commented: Very nice solution +8
a1eio 16 Junior Poster

hmm.. what module is this 'call' function from?

because it's not a builtin / keyword function

a1eio 16 Junior Poster
>>> string = "A simple example string."
>>> if 'example' in string:
	print 'the word \'%s\' is in: "%s"' % ('example', string)

	
the word 'example' is in: "A simple example string."
>>>
a1eio 16 Junior Poster

http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/

An excellent relatively short tutorial about threads, it's brief (4 pages) but i found it very useful.

As much as thread.start_new_thread() looks simple i recommend using the threading module instead, it's just better practice.

Hope that helps,
a1eio

a1eio 16 Junior Poster
>>> exec("print 2")
2
>>> exec("print 2+2")
4
>>> exec("vars = (var1, var2, var3, var4) = 'a', (1,'2',3.0), 44, 0.7\nfor v in vars:\n    print v, '=', type(v)")
a = <type 'str'>
(1, '2', 3.0) = <type 'tuple'>
44 = <type 'int'>
0.7 = <type 'float'>
a1eio 16 Junior Poster
playerScores = {"player1":0, "player2":0}
...
...
if player1 won:
    playerScores["player1"] += 1
elif player2 won:
    playerScores["player2"] += 1

for player in playerScores.keys():
    if playerScores[player] >= 5:
        print player, "won"
        restart game

First line creates a dictionary, pseudo if statements show how you can add 1 onto each players score if they won.

Last section simple iterates through each player in the dictionary, and then checks to see if their score is more than or equal to 5, if it is, then it prints the player won.

a1eio 16 Junior Poster

Well if your running your tkinter gui by calling: root.mainloop() or something similiar then you should change that to:

while 1:
    root.update()
    #repeat code here

You do everything as normal but then when you get to the displaying part, you enter a loop which updates the gui and runs whatever code you need running... there is a rather nasty drawback to that, if some code in that loop either hangs or takes a while to execute then your gui is also going to freeze. In my opinion the easiest way would be to use threads, and just thread either the gui or whatever function you have that blocks the rest of the program

a1eio 16 Junior Poster

Hi all!

Just wondering if it was possible to be able to create a Tkinter window that can handle files being 'dropped' on it.

What i want is to be able to drag a file from an explorer window to a widget on my program (probably an Entry widget) and then take the path of that file and put it into the said widget.
Is this possible using a Tkinter GUI ??

Thanks all
a1eio

a1eio 16 Junior Poster

http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/

A guide to threading i found very useful

a1eio 16 Junior Poster

Personally i would use threading (thats the short answer)
As far as how to go about it, you've got a big project on your hands.

a1eio 16 Junior Poster

don't hijack eggowaffles thread ramakrishnakota, if you need help and it's not related to this guy start a new thread

a1eio 16 Junior Poster

did you define gold?
gold = gold + 5

if 'gold' is not defined before that statement then it doesn't know what to add 5 onto.

a1eio 16 Junior Poster

Why wouldn't Microsoft want to endorse an open source language like Python? What would they lose?

competition?
easier for a giant like MS to keep python in 'check' than allow another powerful open source language like python which could result in a drop in sales if software becomes easier to develop and cheaper/free to buy??

a1eio 16 Junior Poster

1.1 What is Jython?

Jython implements the Python programming language on the Java(tm) Platform. It consists of a compiler to compile Python source code down to Java bytecodes which can run directly on a JVM, a set of support libraries which are used by the compiled Java bytecodes, and extra support to make it trivial to use Java packages from within Jython.

from - http://www.jython.org/Project/userfaq.html

a1eio 16 Junior Poster

java is just like python, it's just that java's virtual machine is a hell of a lot more widely spread, known and used than pythons interpretter.

why do you think Jython is so good at what it does.

a1eio 16 Junior Poster

hahahaha!!!! i was typing away and hit enter without even pasting the link in :)
terribly sorry

http://docs.python.org/ref/customization.html

a1eio 16 Junior Poster

i'm not sure, i havn't used the double underscore methods much (if at all) but as far as i am aware, the __str__ method links with the 'print' keyword, so if print object is called then that objects __str__ method would be called and the result (returned value) of that would be displayed if it was a string, otherwise it returns an error.
So i'm not really sure if there's a method to return a list.

I am currently looking through the following page to see what kinda things you can do. You will probably find it useful also, although sometimes the documentation is a bit hard to understand (i think so anyway).

hope that helps
a1eio

a1eio 16 Junior Poster

well, if you want to be able to 'print' the kangaroo instance in your case your trying to print 'kanga' then just make the '__str__' method return a string and that string will get printed:

...
...
    def __str__(self):
        return str(self.pouch)
....
....
kanga = Kangaroo()
roo = Kangaroo()
kanga + roo
print kanga

i get:

>>> 
[10]
[100]
[10, 100]
>>>

hope that helps
a1eio

a1eio 16 Junior Poster

not sure what you mean exactly, but why are you creating a temporary instance of Kangaroo in the put in pouch function?
I thought you meant you wanted roo's pouch added into kanga's pouch?

if thats the case then your code is fine, except you need to define pouch in init.

class Kangaroo:
    def __init__(self, contents=10):
        self.pouch = []
        self.pouch.append(contents)
...
...
...
    def put_in_pouch(self, other)
        self.pouch.extend(other.pouch)

master = Kangaroo('master')
for i in range(10):
    master + Kangaroo(i)

print master.pouch

my result is:

>>> 
['master']
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
['master', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>

hope that helps
a1eio

a1eio 16 Junior Poster

oh my goodness that is all i needed to know!!

thankyou v.much:)

a1eio 16 Junior Poster

hehe, nicely put vega, i totally forgot about that beautiful aspect of python

a1eio 16 Junior Poster

Hi,

I'm wondering how your supposed to find out a widget's width in tkinter..

Little example code to explain (doesnt do anything at all)

class CustomWidget(Tkinter.Frame):
    def __init__(self, master, **kw):
        apply(Tkinter.Frame.__init__, (self, master), kw)

        self.masterWidth = # ???? Totally stuck, tried obvious things like master.width

class MainWindow(Tkinter.Toplevel):
    def __init__(self, master, **kw):
        apply(Tkinter.Toplevel.__init__, (self, master), kw)

        subwidget = CustomWidget(self)
        subWidget.pack()

thanks in advance
a1eio

a1eio 16 Junior Poster

python has defiantly spioled me!

i hate the look of other languages even tho i'd love to learn them.. whenever i try.. i end up going back to python just cause it's so much clearer and quicker to make things.

i just wish it was a bit easier to create standalone programs that don't need the interpreter running. (i've tried py2exe but i just can't get my head round it)

a1eio 16 Junior Poster

thanks.

Yea i'm using the text version for now, for simplicity and so i can get the rest of the program running, but i'll probably try to work out a canvas method later. i'll post it if it works, cause i had a hard time finding anything on google

a1eio 16 Junior Poster

not sure what you mean by adding fonts,
but when you create a font object, you can specify a pygame font, or a path to a custom font of your choice.

font1 = pygame.font.Font("C:\customfont.ttf", 12)
vegaseat commented: nice help +8
a1eio 16 Junior Poster

hi vega,

thats brilliant, my method involved updating a label with the text all shuffled 1 place to the left each time.

I'm having some trouble understand your slicing method. I can't quite work out what the +20 is for, is that just a number 'that works' or is it to compensate for the 20 spaces padding the text, or is it for the width of the text wiget.. or are all those numbers infact linked.

thanks in advance.
a1eio

a1eio 16 Junior Poster

Hi,

I was wondering how someone would go about making a scrolling ticker or marquee using Tkinter in such a way that allows you to easily add on text and remove.. kinda like a news scroller on the bottom of the tv?

thanks all
a1eio

a1eio 16 Junior Poster

Hi,

download numpy here: http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103

download matplotlib here:
http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=82474

install both and you should be set to go,
drawing a simple graph and displaying it is as simple as:

>>> from pylab import *
>>> plot([1,2,3,4])
[<matplotlib.lines.Line2D instance at 0x01A34BC0>]
>>> show()

Obviously you can do a lot more than that, there is a pretty good tutorial on using it here:
http://matplotlib.sourceforge.net/tutorial.html

a1eio 16 Junior Poster
class testClass:
    def show(self, data):
        print data

def Function(data):
    variable.show(data)

def Main():
    variable = testClass()

    Function("hello")

if __name__ == '__main__':
    Main()

I want 'Function' to be accesible in that way, thats just an example, in the program 'Function' is needed like that elsewhere.
At the moment i'm just making the 'variable' global in the Main function where variable is defined and in 'Function' where it's used so..

def Function(data):
    global variable
    variable.show(data)
...
...
def Main():
    global variable
    variable = testClass()
...

it works, but i wish there was a way without globals

a1eio 16 Junior Poster

it's never too late to learn python :)
awesome language, you'll pick it up quick and it beats VB (in my opinion)