Re: [Tutor] Tkinter help?
On 18/05/15 19:27, cartman6921 wrote: *Below is a code made by me in 5 minutes, I am new to Tkinter so am kinda noobish. We all have to start somewhere. Unfortunately there are a few issues with your code. I'll try to deal with them as we go through. from tkinter import * root=Tk() root.title("Lemonade Stand") root.geometry("500x500+500+300") lemon=0 def BuyLemon(): str(lemon)+str(1) print(lemon) This function doesn't do what you think it does. The second line takes the string representation of lemon ('0') and adds the string representation of 1 ('1') using string concatenation to produce '01' Then it throws it away. Finally it prints lemon which remains unchanged as zero. You need to have an assignment inside the function that modifies lemon. But because you are modifying a global variable you need to declare lemon as global inside the function. So you get: def buyLemon(): global lemon lemon = str(lemon) + str(1) print (lemon) However if you just use that function you will wind up, after 4 presses, with '0' which is not what you want. Instead of converting to strings just add the numbers: def buyLemon(): global lemon lemon +=1 print (lemon) button = Button(root,text="Buy Lemon x1", command=BuyLemon) button.pack() root.mainloop() Once you get that working your next step should be to get the output printed on the GUI rather than the console. For that you should probably start with a Label widget. You can then assign the string representation of lemon to the text attribute of the label. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter help?
*Below is a code made by me in 5 minutes, I am new to Tkinter so am kinda noobish. as you can see, lemon equals 0 at the start and when you click the button it adds 1 to the amount lemon equals. After about 15 minutes of trying and 10 minutes googling i can find nothing to help me. when the code loops, lemon is set back to 0 again, how do i stop lemon from being set back to 0. I need it so if you press the button eg 4 times, lemon=4* from tkinter import * root=Tk() root.title("Lemonade Stand") root.geometry("500x500+500+300") lemon=0 def BuyLemon(): str(lemon)+str(1) print(lemon) button = Button(root,text="Buy Lemon x1", command=BuyLemon) button.pack() root.mainloop() -- View this message in context: http://python.6.x6.nabble.com/Tkinter-help-tp5095151.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Apache cgi Python Sockets classic Linux permissions and SELinux under Fedora19
Hi Thanks to recent help from Alan Gauld and Felix Dietrich I have studied the 'classic Linux ' permissions to allow an Apache cgi script to connect to a Python Socket. Though I became convinced that the corrected permissions were correct the Python cgi script still would not work when called from apache even though all was OK when the cgi script was executed directly by a user. I have found that SELinux provides further access constraints. The Fedora SELinux graphic tool and associated 'trouble shooter' parser of the SELinux audit file made suggestions that worked for TCPIP Sockets but failed for Unix Sockets. (I only experimented with Unix Sockets since I could not get TCPIP Sockets to work). Below is the textual response from the trouble shooter for TCPIP and Unix Socket connect failures . I found that assigning PORT_TYPE to dns_port_t worked for TCPIP sockets. SELinux is preventing /usr/bin/python2.7 from name_connect access on the tcp_socket . If you want to allow /usr/bin/python2.7 to connect to network port 1080 you need to modify the port type. # semanage port -a -t PORT_TYPE -p tcp 1080 where PORT_TYPE is one of the following: dns_port_t, kerberos_port_t, ocsp_port_t. SELinux is preventing /usr/bin/python2.7 from write access on the sock_file /test/uds_socket. Plugin: catchall_labels you want to allow python2.7 to have write access on the uds_socket sock_fileIf you want to allow python2.7 to have write access on the uds_socket sock_file You need to change the label on /test/uds_socket # semanage fcontext -a -t FILE_TYPE '/test/uds_socket' where FILE_TYPE is one of the following: avahi_var_run_t, httpd_sys_rw_content_t, httpd_tmp_t, lsassd_var_socket_t, mysqld_db_t, mysqld_var_run_t, nscd_var_run_t, nslcd_var_run_t, pcscd_var_run_t, postgresql_tmp_t, postgresql_var_run_t, setrans_var_run_t, sssd_var_lib_t, winbind_var_run_t. Then execute: restorecon -v '/test/uds_socket' I hope this will be helpful to others wishing to use apache to connect to python sockets via cgi scripts. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Implementing a Media Streaming Server in Python
I was looking to implement a media streaming server in python, which can stream movies to mobile based clients efficiently to multiple clients (over 50 clients ) Should I just use plain sockets to create connection or should I go with a framework like twisted/flask? I want to know what would be the best way to design the video/media streaming server? Thank you. -- Regards, Anubhav Yadav ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Stem and leaf plots
On Sun, May 17, 2015 at 02:50:39PM -0700, Danny Yoo wrote: > I was reading the "Cartoon Guide to Statistics", and came across a > description on "Stem and plot diagrams". > (http://en.wikipedia.org/wiki/Stem-and-leaf_display.) It's sorta like > a histogram diagram, but bundles by the ten's digit, and uses the > one's digit as the "point". > > Here's my attempt at describing it as a program: > > ### > """ > Stem and leaf plotting. > http://en.wikipedia.org/wiki/Stem-and-leaf_display. > """ > > import collections > import sys > > > def printStemPlot(values): > """Prints a stem plot of the values.""" > stems = collections.defaultdict(list) > for v in values: > stems[v / 10].append(v % 10) > > low, high = min(stems.keys()), max(stems.keys()) > padding = len(str(high)) > for i in range(low, high+1): > stems[i].sort() > print(str(i).ljust(padding) + ' | ' + > ' '.join(map(str, stems[i])))def printStemPlot(values): Nice! It doesn't cope with Stem-and-leaf plots in their full generality, e.g.: stem-widths which are not 10: 4 | 1 2 2 4 | 5 7 9 9 9 5 | 0 0 3 | 5 8 and you should print the stem and leaf width and give a key, but it's otherwise excellent. Thank you for sharing! -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor