You could display the path your program gets from the user in a Tkinter Label positioned below the buttons?
vegaseat commented: Very nice solution +8
You could display the path your program gets from the user in a Tkinter Label positioned below the buttons?
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?
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.
For more information on threading read this excellent 4 page tutorial:
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
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
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
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))
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)
python has a keyword function in
that would be useful in your example.
if password in pass_list1:
# do something
can you post the traceback? and what module's are you using?
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
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.
# 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 …
excellent, happy coding
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'))
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.
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)
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
n = float(2)
m = float(3)
print n/m
Or
n = 2.0
m = 3.0
print n/m
Hope that helps.
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 …
hmm.. what module is this 'call' function from?
because it's not a builtin / keyword function
>>> 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."
>>>
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
>>> 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'>
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.
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
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
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
A guide to threading i found very useful
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.