Why widgets become 'NoneType'?

2011-12-21 Thread Muddy Coder
Hi Folks,

I was driven nuts by this thing: widgets lost their attributes, then I
can't configure them. Please take a look at the codes below:

from Tkinter import *
canvas = Canvas(width=300, height=400, bg='white')
canvas.pack(expand=NO, fill=BOTH)
pic = PhotoImage(file=img)
canvas.create_image(0, 0, image=pic)
al = PhotoImage(file='a.gif')

lbl = Label(canvas, text=x, fg='red').pack(side=LEFT)

canvas.create_text(40,20, text='Howdy')

the last line of code got error message, says canvas object has no
attribute of config.  The same problem happened again, the code is
below:

def make_labels(win, astr):

labels = []
for i in range(len(astr)):
lbl = Label(win, text=astr[i]).pack(side=LEFT )
labels.append(lbl)
return tuple(labels)
def config_labels(atuple, func):
for lbl in atuple:
lbl.config('%s') % func

root = Tk()
lbls = make_labels(root, 'foobar')
config_labels(lbls, fg='red')

The config for Label was picked up: No attributes of config. I tried
to print type(lbls), and found Python interpreter reported as
'NoneType'. I also tried to print out dir(lbls), fount there was no
attributes I familiar with such as config and such. What is wrong with
them? Both of the codes above WORKED, since I saw my widgets displayed
them as I wanted, but I just can't configure them as I usually did.
Can somebody help me out? I never experience such a weird thing.
Thanks!

Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


What is this widget?

2011-12-14 Thread Muddy Coder
Hi Folks,

I am trying to write letters on a photo that is opened in a canvas. So
I think I must need a widget to contain the letters I will type in. I
tried to use a Label, it worked. But, a Label covered part of the
photo underneath, so I can't use it. I saw some software did such a
thing nicely: a box popped on a photo, with dotted lines as borders,
expandable. When such a box was re-sized with a mouse, the font size
in the box also got changed. The box has no background color, so it
does not cover a rectangle area on the photo. I need such a widget,
but I don't know what is this one. I tried Text, Label, but they all
come with Window-like stuff, so they cover some photo content. Can
somebody points me a direction? Thanks!


Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


What is this widget? -- again

2011-12-14 Thread Muddy Coder
Hi Folks,

Sorry for the unclear question in last post. Well, I am using Tkinter
to do GUI, and I just don't know what kind of widget can let me do
annotation on an image being displayed. An example is the Paint of
Windows: a dotted line box appearing on a image to hold a typed in
text. I just can't figure out what widget in Tkinter is equivalent to
that dotted line box. Please help, thanks again!


Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


How to use a color value returned by colorChooser?

2011-12-14 Thread Muddy Coder
Hi Folks,

This should be a simple question, but I just can't get an answer from
Phython Docs. You see, when we created a widget, and need to tweak the
color, we just simply configure it, such as:

abutton = Button(root, text='Foo')
abutton.config(fg='blue')

so we can make the Button color in blue. However, when I choose a
color by a color Dialog, askcolor, and then I will get a color value
as:   (0, 0, 255) . So, I want to use this returned color value to
configure my existing widgets, with widget.config() syntax. The Python
interpreter does not take it. Therefore, I think I must need to covert
this returned color value into a symbolic name, such as 'blue', 'red'
and so on, then the widget.config() syntax can be used. How can I
convert this color value? Please help, thanks folks!

Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


How to move scrollbar by code?

2011-12-09 Thread Muddy Coder
Hi Folks,

I am trying to make a listbox that will contain a looong data list,
sorted, so I will be able to pre-select a data line by coding. I have
done it. Say my listbox contains 1000 data lines, and my program has
figured out the data line 321 is needed, so just put the cursor on
data line 321. However, my scrollbar is still seating on the top, so I
just can view the data line from line 0 to 30 or 40, since I can't see
the desired data line 321.  I still need to manually pull the
scrollbar down to display the data line 321. What I want to do is to
grab the adjacent data lines, say from line 300 to 340, and display
this lines, while my cursor seating in the middle. I consulted the
Python Docs, but did not find such details. Can somebody give an idea?
Thanks!


Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


How filecmp walk into subdirectories?

2011-11-01 Thread Muddy Coder
Hi Folks,


I tried to compare two directories, each with hundreds of files in
multiple level subdirectories, to find out the different files. I used
filecmp module to the job as:


comp=filecmp.dircmp(adir, bdir)
comp.report()

It worked, and printed out the identical and different files. However,
it did not go through the directory trees, just did the job in the
first level. I wonder somebody can help? Thanks in advance!


Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


Hide DOS console for .pyc file

2010-09-10 Thread Muddy Coder
Hi Folks,

For a quick testing purpose, I deliver .pyc files to my customer. I
don't want the black DOS console appearing behind my GUI, but I have
no idea how to do it. Somebody can help? Thanks!


Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


Where to find options for add_command?

2009-04-15 Thread Muddy Coder
Hi Folks,

When I make Menu, and add in menu items, by using add_command, such
as:

menuObj.add_command(label='Open File', command=self.open_file)

It works. But, I want to make the GUI looking better. So, I want to
change color, font, size, background, for the label of Open File. I
got clobbered. I tried relief, fg, color, no one worked. Can somebody
points me a website to visit, to check out what options available for
add_command? Thanks!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


How to query object of GUI?

2009-04-14 Thread Muddy Coder
Hi Folks,

I need to query the ID of GUI, in Tkinter, but don't know how to do
it. This is my code:

calss MyGUI:
   
   def make_menu(self):
  top = Menu(self)
  menObj = Menu(top)
  labels = read_from_database()
  for lab in labels:
 menObj.add_command(label=lab, command=self.do_menu)
   def do_menu(self):
  # here I need query which menu item was clicked

For GUI Entry, there is a resource name textvariable, so I can use
textvariable to distinguish one Entry from the others. But, I can't
find such a resource name for Menu. I also noticed label is an
identifier, but I have no idea how to get it. Can somebody help me
out? Thanks in advance!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


How can I change size of GUI?

2009-04-06 Thread Muddy Coder
Hi Folks,

I copied code from book:

class ScrolledText(Frame):
def __init__(self, parent=None, text='', file=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets()
self.settext(text, file)
def makeWidgets(self):
sbar = Scrollbar(self)
text = Text(self, relief=SUNKEN, width=120)
sbar.config(command=text.yview)
text.config(yscrollcommand=sbar.set)
sbar.pack(side=RIGHT, fill=Y)
text.pack(side=LEFT, expand=YES, fill=BOTH)
self.text = text

It works, of course. But, the GUI is small, and I want to enlarge it.
I tried to add in options of width=120 for Text(), but it did not
work. Can somebody drop me a couple of lines for help? Thanks!

Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Help for Toplevel

2009-04-01 Thread Muddy Coder
Hi Folks,

I have a problem of handling Toplevel window. Basically, I wrote a
listbox viewer with scrollbars, and saved in file listbo.py. Then in
my main GUI window, with menu, I need to launch the listbox viewer, in
a new window. Obviously, a Toplevel window is needed. But, I failed at
passing parameters over to Toplevel window. Please take a look at my
code:

Listbox viewer:
class ScrolledList(Frame):
def __init__(self, options, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(options)

In my main GUI:
from XXX import ScrolledList
class Foo:
 def __init__(self):
 
 def call_listbox(self, params):
   new = Toplevel()
   alist = ['foor','bar']
   ScrolledList(new,alist)

With the code above, the widgets did not show on the Toplevel window,
and the data list ['foo','bar'] did not show up either. Can somebody
help me on it? Thanks a lot!

Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


How to access object created in Main?

2009-03-29 Thread Muddy Coder
Hi Folks,

I need to update the text field of a Label created in Main, but can't
find a way to do it. Please take a look at my code:

from Tkinter import *

def makemenu(r)
   amenu = Menu(r)
   amenu.add_command(., command=update_label)

def update_label():
how to access mesg created in __main__ ?

if __name__ == '__main__':
root = Tk()
mesg = Label(root, text='foo\nbar\nfoo')
mesg.pack(expand=YES, fill=BOTH)
root.mainloop()

What I need to do is simple: when Menu (amenu) is clicked, it should
execute update_label function that is expected to update the text of
Label mesg in MAIN, with a syntax like: mesg.config(text='new text')
What I don't know is the path of accessing this object mesg. I tried
root.mesg, no good. I am confused here: since mesg is created on root
as its master, why root.mesg is not its path? Can somebody help me
out? Thanks a lot!

Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


SWIG: Window syntax help

2009-03-26 Thread Muddy Coder
Hi Folks,

I am learning SWIG, with a doggy C file test.c. I have made test.i,
the interface file, then I ran:

C:swig -python test.i   --- smooth
C:cl -c test.c test_wrap.c -IC:\Python25\include   nice,
test.obj, test_wrap.obj, test.py files were created

But the final step I got error message by running this:
C:cl -shared test.obj test_wrap.obj -o test.dll

It did not take -shared  and -o

I tried to follow the example of the DOCS, and modified the syntax of
unix. Can anybody help me to get a right syntax for Windows? Thanks!

Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Does Python have certificate?

2009-03-23 Thread Muddy Coder
Hi Folks,

I wonder that does Python have certificate? You see, java, .NET, PHP,
and so on, they have certificates for developers to get. Python is
quite popular nowadays, I wonder is there such a thing? If so, I
certainly want to get one. I searched, and


Muddy Coder

--
http://mail.python.org/mailman/listinfo/python-list


How to define a db file for sqlite?

2009-03-07 Thread Muddy Coder
Hi Folks,

I just downloaded and installed pysqlite, and I can import sqlite3
smoothly. Then, I need to connect sqlite by syntax:

conn = sqlite3.connect('adirectory/db')

I wish the data will be stored into directory --- adirectory, with a
file named in db. But I got kicked out with an error message as:

Unable to open database file

I wonder: does pysqlite open a database file db for me? Or, do I need
to create an empty file inside adirectory with my text editor? Anyway,
somebody please help me out here. After I can connect it, the rest
will be easy to go, thanks!

Muddy coder
--
http://mail.python.org/mailman/listinfo/python-list


Can Python do shopping cart?

2009-03-05 Thread Muddy Coder
Hi Folks,

I know PHP can do shopping cart, such as Zen Cart. I wonder can Python
do such a thing? Thanks!



Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


How to import Python files in the other directories?

2009-03-05 Thread Muddy Coder
Hi Folks,

If I have a python file foo.py in the current directory, I can simply
import it in the way below:

import foo

when a project keeps grow, more and more Python files are created, and
they are also needed to put into different directories. Then, a
problem comes: how to import the Python files residing in the other
directories? Somebody helps me out? Thanks!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Is it possible to grab hidden code in ClientForm?

2009-03-01 Thread Muddy Coder
Hi Folks,

Nowadays some websites let users to fill in some so-called
verification code, and the tricky thing is that the CODE is delivered
from server with an image. For example:

img src=/jobsearch/captcha.jpg name=CAPTCHA_IMAGE border=1 /
nbsp;nbsp;a href=# onClick=changeSource();Refresh Image/a

When click Refresh Image, the CODE on the image changes. I wonder:
does the server really send a new image over to browser, or just send
a hidden code over? Is it possible to parse out such hidden code?

The other example is:

img src=/images/verify.png;jsessionid=ahZsBmwyLGuf alt=Digital
Signature Code /
input name=jsessionid type=hidden value=ahZsBmwyLGuf /

I did a few REFRESH on browser, and noticed the CODE changed. But,
when I viewed the HTML source code, the value ahZsBmwyLGuf remained
the same. What is the trick around here? That is why I am wondering
whether the server really keeps sending new images over, or just
sending new hidden codes over. If the trick is just keep sending
hidden codes over, there might be a chance of capturing the codes. Can
somebody help me out? Thanks a lot!


Muddy Coder





--
http://mail.python.org/mailman/listinfo/python-list


Can CleintForm work with webbrowser?

2009-03-01 Thread Muddy Coder
Hi Folks,

ClientForm is cool at grabbing and parsing stuff from server, I like
it. After the stuff parsed, and even filled values for the Controls, I
popped up an idea of displaying what I had done with webbrowser. Look
at the code:

import ClientForm
import urllib2
import webbrowser

request = urllib2.Request(url)
response = urllib2.urlopen(request)
forms = ClientForm.ParseResponse(response, backwards_compat=False)
...parsing and filling forms

# now I want to display the forms I modified, with webbrowser
webbrowser.open_new_tab (???)

??? is supposed to be a url. But this moment I want to display the
form I filled. Obviously webbrowser takes url as argument rather than
a form.  Is there other options to do this? Somebody can help? Thanks!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Bug report: ClientForm

2009-02-28 Thread Muddy Coder
Hi Folks,

As directed, I got ClientForm and played with it. It is cool! However,
I also found a bug:

When it parses a form, if the VALUE of a field has not space, it works
very well. For example, if a dropdown list, there many options, such
as:

option value=foo 

the value foo will be picked up for sure. But, if there is a space:

option value=foo bar .

The *bar* will be missed out. I wish this bug can be fixed in near
future.

By the way, can somebody helps me on setting parameter of uploading a
file. In ClientForm, if I need to upload a text file, I can do it by:

form.add_file(..., text/plain)

What about a picture file? What is the counterpart of 'text/plain?
Thanks!

Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


How to parse form in client side?

2009-02-26 Thread Muddy Coder
Hi Folks,

cgi module can easily acquire the all fields of data input from client
side, through a form. Then, a simple line of code:

form_dict = cgi.FieldStorage()

grabs all data into a dictionary form_dict. The rest becomes a piece
of cake by querying the form_dict. Nice!

However, it is done in the server side. Now I want to do the same in
the client side. first of all, I get the source code of a HTML form by
using urllib, from server, with code below:

html_source = urllib.urlopen(URL).read()

Then, I need to parse this html_source file, at client side. Is there
a module to handle this? Can somebody help? Thanks!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Help: makefile in Windows

2009-02-12 Thread Muddy Coder
Hi Folks,

I am learning Extending Python, by testing the demo script of
Programming Python. In the book, a makefile for Linux is there, but I
am using Windows currently. I wish somebody would help me to get a
makefile for Windows, my makefile.linux is as below:

PYDIR= c:\Python25
PY = $(PYDIR)

hello.so: hello.c
gcc hello.c -g -I$(PY)/include -I$(PY) -fpic -share -o
hello.so
clean:
   rm hello.so core



Thanks a lot!


Muddy Colder
--
http://mail.python.org/mailman/listinfo/python-list


Can I 'LOOK' through urllib?

2009-02-11 Thread Muddy Coder
Hi Folks,

I feel good after played urllib with fun!

Now I want to LOOK to server through urllib. I read the urllib docs,
but I did not find such a function. For example, if there are many
files located in http://www.somedomain.com/data_folder, but I don't
know what the filenames are residing in the data_folder. I wish urllib
would have a function to let me do it, as well as I do 'dir' in DOS,
'ls' on unix/linux. Somebody write me a demo? Thanks!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Can urllib check path exists on server?

2009-02-10 Thread Muddy Coder
Hi Folks,

urllib bridges up a client to a server, it works fine. I wonder: is
there a method that can check the existence of a file in the server
side? We can check such an existence on local filesystem by using
os.path.exists(), can I do such a check on server? For example,
http://somedomain.com/foo/bar.jpg is residing in a hosting server, can
I use urllib to check if bar.jpg file existing or not? Thanks!

Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


How to get a return from Button?

2009-02-10 Thread Muddy Coder
Hi Folks,

I want to use a Button to trigger askopenfilename() dialog, then I can
select a file. My short code is below:


def select_file():
filenam = askopenfilename(title='Get the file:')
   return filenam

root = Tk()
Button(root, text='Select a file', command=select_file).pack()
root.mainloop()

My goal is to get the path of filenam, but the function select_file()
has nowhere to return what it selected. Can anybody help me out? I
consulted the book of Programming Python, but found no demo in this
regard. If the function has no return, command=blabla will work
nicely. I am lost in the scope.

Thanks!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


urllib2: problem of handling space in parameter

2009-02-07 Thread Muddy Coder
Hi Folks,

I encrountered a problem of using urllib2: the space handling. Look at
the code below:

import urllib2
url = r'http://somedomain.com/a.cgi?name=muddy coderpassword=foobar
cgi_back = urllib2.urlopen(url).read()

In this cgi_back, I saw field password worked fine, but field name
not, only muddy was picked up by CGI. So, I had to cover the space, by
using syntax name=muddy-coder, it went through. So, I presume urllib2
may have an approach of handling white space in this regard. Can
anybody help? Thanks!

Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


How to trigger a smart link?

2009-02-04 Thread Muddy Coder
Hi All,

Using urllib2 can trigger CGI script in server side. However, I
encountered a problem of the so-called smart link. When a fairly large
site, the server needs to track the identifier of each request from
client, so it generated an ugly escape string attached on url. It
seems that I must get this ugly escape string first then I can can
fill the string into my url, and the CGI script on server side can be
triggered. For example,

http://whatever.com/submitreal.cgi?fp=3xD0TuGMp7C7gP1TRD

displays a submit form. If I just copy

http://whatever.com/submitreal.cgi

to url address, without the escape string ?fp=3xD0TuGMp7C7gP1TRD, the
browser will report error of 404

I found Python has a module of escape, but I don't know how to use
this module to solve the problem above. Or, I just wonder does urllib2
has such a method to handle smart link? Thanks!


Moddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Results of executing hyperlink in script

2009-01-28 Thread Muddy Coder
Hi Folks,

My previous post got a many helps from the people, and I tested what
they suggested. Since this topic maybe needed in future, so I drop
these lines below to help the future programmers. The methods worked
as below:

1. This method was suggested by Cameron Laird:

  os.system(start %s % URL)

It works. But, if the URL contains character , it will fail. For
example, if URL has only one field, such as: 
http://www.mydomain.com/ascript.cgi?user=muddy
this method works well. But, if there more than one field need to be
input, such as http://www.mydomain.com/ascript.cgi/user=muddypassword=foo,
the field password failed to reach server, and the CGI script
complained.

2. The best way is to use urllib2, suggested by Ron Barak, my code is
below:

import urllib2
source = urllib2.urlopen(URL).read()
print source

It successfully triggered CGI script, and also got feedback from
server. It works very well!

My thanks go to all the helpers!

Muddy Coder

--
http://mail.python.org/mailman/listinfo/python-list


How to execute a hyperlink?

2009-01-27 Thread Muddy Coder
Hi Folks,

Module os provides a means of running shell commands, such as:

import os
os.system('dir .')

will execute command dir

I think a hyperlink should also be executed. I tried:

os.system('http://somedomain.com/foo.cgi?name=foopasswd=bar')

but I got kicked out by the Python interpreter. I wonder somebody
knows the syntax of triggering a hyperlink? Thanks in advance!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list


Can webbrowser module get source code?

2009-01-24 Thread Muddy Coder
Hi All,

I played the demo of webbrowser module, with the code below:

import webbrowser
url = 'https://login.yahoo.com'
webbrowser.open_new_tab(url)

when I ran the code, it popped out a webpage nicely. I want to go
further: to get the source code of the webpage being displayed. Is it
possible to do it? I tried webbrow.get() but didn't work. Somebody can
help? Thanks!


Muddy Coder
--
http://mail.python.org/mailman/listinfo/python-list