Re: [Tutor] Displaying picture and Text
wrote of my python program where a picture is supposed to display with a few lines of text below it. To do this you will need to use some kind of GUI. The simplest option is probably to use the Text widget in Tkinter which can display both Images and text. Ideally, I would like this to stay on the screen for a short period of time (2 minutes?) You would do that with a Timer event in Tkinter. import Image fhdl = Image.open("C:\Users\StarShip\PyProgs\\bbsparkle.gif") fhdl.show() I've never used Image but I assume the show() method just invokes the default viewer on the system. print "here is some test text test text test text" print "here is some more test text test text test text" print "here is even more of some test text test text test text" print will always go to stdout, wherever that is defined to be.. How do I get any picture to display on half a screen then my print text display below that and stay on screen for 2 or 3 minutes before I call another function that will redraw the screen anyway - it will be interactive text responses with the user. Also this is a test .gif file, I may want to just edit the source file and change this to a .jpg. The Tkinter PhotoImage object can display jpg. I can't recall if it does gifs. If you want to habndle many types yoyu may need to look at using an image convertion library too. I don't want to change the system defaults for this, maybe for the picture itself if that is necessary. That should not be necessary, if you tell Python the filepath it can load the specific file you select. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Displaying picture and Text
On 04/11/2010 04:24, pa...@cruzio.com wrote: Hi - I am running Python 2.6.6 on my HP netbook with Windows 7. The default picture viewer is set to HP Photo Viewer. I am working on a part of my python program where a picture is supposed to display with a few lines of text below it. Ideally, I would like this to stay on the screen for a short period of time (2 minutes?) but I am using raw_input() for now. I imported the Image library and when I run the program below, it brings up a window (stdout or python?) with cursor flashing for a few seconds and then the HP Photo Viewer comes up with the picture, I close this window and then my text comes up in a python window. The Image.show function in the PIL is simply a convenience for doing a quick-and-dirty "What does this image look like?". It hands off to the default image viewer -- as you discovered. It's not intended for use in a production program which needs to control image size, placement etc. There probably *are* image viewers which you could control from the command line to display what you want, but if you're going to need a solution involving text and images, just use one of the existing GUI toolkits: wxPython, PyQt or others (just search for "Python GUI") which let you display text, images etc. with complete control. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Displaying picture and Text
"Alan Gauld" wrote ...a picture is supposed to display with a few lines of text below it. To do this you will need to use some kind of GUI. The simplest option is probably to use the Text widget in Tkinter I just had a thought. The simplest option might be to use HTML to create a simple web page and display that in a browser. However the extra features you require will probably be easier in a GUI.But its another option to consider. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Displaying picture and Text
On Thu, Nov 4, 2010 at 3:58 AM, Alan Gauld wrote: > > wrote > > > of my python program where a picture is supposed to display with a few >> lines of text below it. >> > > To do this you will need to use some kind of GUI. > The simplest option is probably to use the Text widget in Tkinter > which can display both Images and text. I'll second the motion. You can probably write the most basic functions in less than 50 lines > How do I get any picture to display on half a screen then my print text >> display below that and stay on screen for 2 or 3 minutes before I call >> another function that will redraw the screen anyway - it will be >> interactive text responses with the user. Also this is a test .gif file, >> I may want to just edit the source file and change this to a .jpg. >> > > The Tkinter PhotoImage object can display jpg. I can't recall if > it does gifs. If you want to habndle many types yoyu may need to > look at using an image convertion library too. PIL (What you have installed to use the Image library) allows you to convert basically any image to a format you can use in Tkinter. There is a short example here: http://stackoverflow.com/questions/1236540/how-do-i-use-pil-with-tkinter HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Displaying picture and Text
Thank you for all the replies - I think I will want to use Tkinter since it also has the timer I am looking for and I do have one book that has a big chapter on using Tkinter. If I find that I am having trouble understanding Python GUI programming. I may be able to copy some code from the book or I will use a workaround of skipping the picture part temporarily, I am sure with time it will all come together. I am liking Python programming! I pretty much consider myself a C programmer plus know several other programming and database querying languages. Patty ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Displaying picture and Text
"Alan Gauld" wrote fhdl = Image.open("C:\Users\StarShip\PyProgs\\bbsparkle.gif") fhdl.show() The Tkinter PhotoImage object can display jpg. I can't recall if it does gifs. Sorry I got that wrong, it can display gifs but not jpgs (despite the fact that jpgs are used more often for photos than gifs!) So you will need to convert the jpg to a gif - which might lose a lot of quality! Anyone know of a way to get decent quality in a Tkinter image? Is there any support in PIL itself? Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] if statement
On 02/11/2010 20.07, Glen Clark wrote: sorry: NumItems = int(input("How many Items: ")) Entries = [] for In in range(0,NumItems): Entries.append("") for In in range(0,NumItems): Entries[In]=str(input("Enter name " + str(In+1) + ": ")) for In in range(0,NumItems): print(Entries[In]) confirmed = int(input("Are you happy with this? (y/n): ") if confirmed == "y": for In in range(0,NumItems): print(Entries[In] + ": " + str(In)) change = int(input("Which item would you like to change: ") Entries[change]=str(input("Please enter a nem name: ") else: #do nothing print(Entries) On 11/2/10, Glen Clark wrote: File "/home/glen/workspace/test.py", line 19 if confirmed == "y": ^ SyntaxError: invalid syntax It seems to me that when you wrote the request for confirmation you just copied and pasted part of the first line, changing the variable name to 'confirmed'. But you were expecting a string, so you should delete the leading "int(" part of that statement, what you forgot to do: confirmed = input("Are you happy with this? (y/n): ") So the problem was not in the missing ending parenthesis, but in those four characters in excess. A very similar mistake is in the request for a new name for Entries[change]: remember that input() ALWAYS returns a string. Entries[change]=input("Please enter a new name: ") Finally, as others have pointed out, you should put a pass statement after the else clause, or delete it altogether: > if confirmed == "y": > for In in range(0,NumItems): >print(Entries[In] + ": " + str(In)) > change = input("Which item would you like to change: ") > Entries[change]=input("Please enter a nem name: ") #the following two lines may be safely deleted, or must be BOTH there > else: > pass Hope that helps, Francesco Nessun virus nel messaggio in uscita. Controllato da AVG - www.avg.com Versione: 9.0.864 / Database dei virus: 271.1.1/3235 - Data di rilascio: 11/03/10 09:36:00 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Advantages or disadvantages on Platform?
Hello all. I am newbie and studying and working hard learning python. Per your advise I am on 2.7 . I have one question for you. I can work on Windows (XP) or under Ubuntu . Do you see any advantages or disadvantanges to be working in one or another ? My main goal , for now, is use Python for web applictions. Thanks in advance for your comments and advice. Jorge Biquez ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Looking for a tutor to review my code and provide constructive feedback.
Hello, I have completed my first python script. This is after watching a video guide on python and is my first attempt at writing code in python. While the code is not very useful I got the idea for it when googling "python projects for beginners". The idea was to create a script that asked the user to input a list of names and allow the user to change a name if he wanted before confirming the entries. I tried to incorporate what I had learnt from the videos, such as conditionals, error handling, functions etc... and write it how I would write code in future. Please if you are kind enougth to take the time to provide feedback I would appreciate that it is constructive :) The script is here: http://bpaste.net/show/10658/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Advantages or disadvantages on Platform?
> -Original Message- > From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor- > bounces+bermanrl=cfl.rr@python.org] On Behalf Of Jorge Biquez > Sent: Thursday, November 04, 2010 3:44 PM > To: tutor@python.org > Subject: [Tutor] Advantages or disadvantages on Platform? > > Hello all. > > I am newbie and studying and working hard learning python. Per your > advise I am on 2.7 . I have one question for you. > > I can work on Windows (XP) or under Ubuntu . > > Do you see any advantages or disadvantanges to be working in one or > another ? Do you see any reasons for not working in both environments? Robert ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor -- I am using the free version of SPAMfighter. We are a community of 7 million users fighting spam. SPAMfighter has removed 34 of my spam emails to date. Get the free SPAMfighter here: http://www.spamfighter.com/len The Professional version does not have this message ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Advantages or disadvantages on Platform?
Am 04.11.2010 20:43, schrieb Jorge Biquez: Hello all. I am newbie and studying and working hard learning python. Per your advise I am on 2.7 . I have one question for you. I can work on Windows (XP) or under Ubuntu . The advantage of using Ubuntu is that you learn how to work in a Linux/Unix environment. Most servers are using Linux/Unix based operation systems. Therefore if your goal is to develop web-apps, I would go for Ubuntu. Also, once you've set up your development environment and know how to work with your shell, working on Linux is incredible fast and fun. I used to work professionally for engineering stuff on Linux/Unix before moving to Windows. Productivity on Linux for OS operations like organising your files and quickly modifing scripts is by far higher than on Windows. Another advantage is, that there're good editors well integrated. If you have the time to learn vim, go for it. After telling you all this, I have to admit that I'm currently on a Windows 7 machine and also perfectly happy. Using an IDE makes the OS less important. Do you see any advantages or disadvantanges to be working in one or another ? My main goal , for now, is use Python for web applictions. Thanks in advance for your comments and advice. Jorge Biquez ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a tutor to review my code and provide constructive feedback.
Also for your confirm entries function, read about while loops - Sent from a mobile device with a bad e-mail client. - On Nov 4, 2010, at 3:10 PM, Glen Clark wrote: > Hello, > > I have completed my first python script. This is after watching a video guide > on python and is my first attempt at writing code in python. While the code > is not very useful I got the idea for it when googling "python projects for > beginners". > > The idea was to create a script that asked the user to input a list of names > and allow the user to change a name if he wanted before confirming the > entries. > > I tried to incorporate what I had learnt from the videos, such as > conditionals, error handling, functions etc... and write it how I would write > code in future. > > Please if you are kind enougth to take the time to provide feedback I would > appreciate that it is constructive :) > > The script is here: http://bpaste.net/show/10658/ > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a tutor to review my code and provide constructive feedback.
Also for your confirm entries read about sentinel values for while loops. It saves you repeating the conditional in the loop body. And you might want to .lower().strip()[0] the input choice so that they can use y, Y, yes, or whatever. Remember, users suck at generating accurate and correct input so don't give them any credit you can avoid. - Sent from a mobile device with a bad e-mail client. - On Nov 4, 2010, at 3:10 PM, Glen Clark wrote: > Hello, > > I have completed my first python script. This is after watching a video guide > on python and is my first attempt at writing code in python. While the code > is not very useful I got the idea for it when googling "python projects for > beginners". > > The idea was to create a script that asked the user to input a list of names > and allow the user to change a name if he wanted before confirming the > entries. > > I tried to incorporate what I had learnt from the videos, such as > conditionals, error handling, functions etc... and write it how I would write > code in future. > > Please if you are kind enougth to take the time to provide feedback I would > appreciate that it is constructive :) > > The script is here: http://bpaste.net/show/10658/ > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a tutor to review my code and provide constructive feedback.
Your code is not bad overall, pretty great for a beginner actually. I would say you should read guido's style guide though; some of your variable and function naming is nonstandard python. - Sent from a mobile device with a bad e-mail client. - On Nov 4, 2010, at 3:10 PM, Glen Clark wrote: > Hello, > > I have completed my first python script. This is after watching a video guide > on python and is my first attempt at writing code in python. While the code > is not very useful I got the idea for it when googling "python projects for > beginners". > > The idea was to create a script that asked the user to input a list of names > and allow the user to change a name if he wanted before confirming the > entries. > > I tried to incorporate what I had learnt from the videos, such as > conditionals, error handling, functions etc... and write it how I would write > code in future. > > Please if you are kind enougth to take the time to provide feedback I would > appreciate that it is constructive :) > > The script is here: http://bpaste.net/show/10658/ > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] argparse: how to use the returned Namespace object?
Hi, I'm writing a small command line utility using the argparse module (I am on python 2.6.6 so that's not in the standard lib, but this should not play any role in my problem, I believe). My goal is to use a class that I already wrote and cannot change for a GUI app, as a command utility, so I would like to simply have the CLI as a wrapping layer, without changing the pre-existing code. The code I want to reuse, accept all keywords arguments, so I wrote my parser in such a way that it returns keywords/values in a compatible way to my method signatures. Example: Let the signature of one of my functions be: def do_stuff(overwrite=False, verbose=False): do-some-stuff-here I wrote the parser in such a way that issuing: utilityname dostuff --overwrite --verbose I get at the end of the parsing process a variable "args" that looks like this: Namespace(command=dostuff, overwrite=True, verbose=True) Now, I tried to do the following: command = args.command del args.command command(**args) But that doesn't work because the Namespace implementation of the argparse result is an object which is not iterable. Of course if I use: args.command(overwrite=args.overwrite, verbose=args.verbose) I get the system working, but the fact is that each command calls a different function / method, each of them with a different signature. My question boils down to: how can I expand the Namespace object in order to get a list of keyword arguments? Thank you for your time, Mac. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] argparse: how to use the returned Namespace object?
On 4 November 2010 23:20, Mac Ryan wrote: > My question boils down to: how can I expand the Namespace object in > order to get a list of keyword arguments? > If "ns" is your Namespace object, then use ns.__dict__, which you can directly pass to your commands, e.g. do_stuff(**ns.__dict__) I'll post a more complete answer if this isn't clear/obvious. HTH Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] argparse: how to use the returned Namespace object?
On Fri, 2010-11-05 at 00:17 +, Walter Prins wrote: > > > On 4 November 2010 23:20, Mac Ryan wrote: > My question boils down to: how can I expand the Namespace > object in > order to get a list of keyword arguments? > > If "ns" is your Namespace object, then use ns.__dict__, which you can > directly pass to your commands, e.g. > > do_stuff(**ns.__dict__) > > I'll post a more complete answer if this isn't clear/obvious. > > HTH Thank you Walter. I got it and it works! :) I have a follow-up question, though. I had previously already inspected "ns.__dict__" with the "dir()" function, but couldn't (and can not) see my parameters neither with "dir(ns.__dict__)" nor with "dir(ns.__dict__.items)". This is clearly an indication that I misunderstand what the __dict__ is and how it works. Yet if I do a dir() on an instance of an object, it does work as expected, returning all attributes of that object. Could you (on anybody else!) help me undertand what I fail to grasp? Thank you! Mac. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Server
Dear Tutors, May server and client programs aren't working. They basically simplify socket and SocketServer. Run them directly to test them. They do work locally. They don't work from one computer to the next on the same network. Please Help. Sincerely, Me, Myself, and I P.S. How to you stop a server loop and open up the port? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Server
Chris King wrote: Dear Tutors, May server and client programs aren't working. They basically simplify socket and SocketServer. Run them directly to test them. They do work locally. They don't work from one computer to the next on the same network. Please Help. It's probably a network issue. Consult with your network administrator. Perhaps the firewall is blocking something? P.S. How to you stop a server loop and open up the port? What's a server loop? What firewall are you using? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] argparse: how to use the returned Namespace object?
On 5 November 2010 00:40, Mac Ryan wrote: > > Thank you Walter. I got it and it works! :) > Excellent. I thought I'd mention here you can also create your own Namespace object (e.g. if you find accessing __dict__ not ideal or something you can do your own implementation, which will work as long as it's got the neccesary features.) > I had previously already inspected "ns.__dict__" with the "dir()" > function, but couldn't (and can not) see my parameters neither with > "dir(ns.__dict__)" nor with "dir(ns.__dict__.items)". This is clearly an > indication that I misunderstand what the __dict__ is and how it works. > You need to distinguish between what __dict__ *is*, and what it *contains*. dir() does introspection, it inspects what an object in Python *is*, e.g. displays all the methods and attributes of the object. It does not however know anything about what (if anything) the object might contain, in the data storage sense. A dictionary object is a specific type of container object, it has many methods but suffice it to say the data (keys and values) inside it are obviously not explicitly exposed as attribues of the dict object itself. So then, dir() on a dict object, shows you the methods and attributes of dict's, but nothing of what data might be inside the dict. Similarly when you dir() your own instance of an object with some custom attributes, then likewise, dir() on the object itself will show you the members and attribues of that object itself. Now, Python makes available a read-only, "hidden" attribute on all objects (e.g. a chiled member/object) called "__dict__", into which it encodes the actual attributes of that object, as key value pairs. So... if you dir() the object *itself*, you get information about *its* attributes, if you however dir() the dict that's part of that object, you'll get a dict's properties, not what is contained inside of the dicts. Best, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor