4,305 Posted Topics
Re: Best to use a grid ... [code=python]# using Tkinter's grid() to place widgets import Tkinter as tk root = tk.Tk() # create some buttons button1 = tk.Button(root, text='button1') button2 = tk.Button(root, text='button2') button3 = tk.Button(root, text='button3') # create a label for kicks label1 = tk.Label(root, text="hello Matty!", fg='red', bg='yellow') # … | |
Re: Only the world renowned modesty practiced by the inhabitants of the state of Minnesota must have prevented Dave from mentioning his many excellent articles on this very subject ... [URL]http://www.daniweb.com/code/snippet597.html[/URL] [URL]http://www.daniweb.com/code/snippet353.html[/URL] [URL]http://www.daniweb.com/code/snippet597.html[/URL] [URL]http://www.daniweb.com/code/snippet357.html[/URL] [URL]http://www.daniweb.com/code/snippet358.html[/URL] [URL]http://www.daniweb.com/code/snippet373.html[/URL] I have used his wisdom in my work repeatedly. | |
Re: [quote=~s.o.s~;312497]Maybe [URL="http://www.daniweb.com/techtalkforums/post311548-4.html"]this[/URL] would interest you...[/quote]I think his TA would look right through that as somebody else's fairly sophisticated code! | |
Re: This is how you can create a list of random (x, y) points ... [code=python]import random as rn # a list of 5 random (x, y) points rp_list = [] for k in range(5): rp_list.append((rn.randint(1, 21), rn.randint(1, 21))) print "Random point list:" print rp_list # eg. [(19, 12), (20, 13), … | |
Re: This has to do with the fact that the Python Interpreter is written in C, not with the Python language intrinsically. So you might better post this in the C/C++ Forum. | |
Re: For things like that you better use: subprocess.Popen() For an example see: [URL]http://www.daniweb.com/techtalkforums/post197119-52.html[/URL] | |
Re: I don't have your files available to test this, but I added try/excepts just in case you have less data in your files than you expect ... [code=python]import string dictString = open('wordlist.txt', 'U').read() dictList = dictString.split('\n') x = 0 newDict = '' while x != 1275: try: letters = list(dictList[x]) … | |
Re: You can code it like this ... v1=input("Insert the first vector (eg, 1,2,3,4): ") v2=input("Insert the second vector (eg. 4,3,2,1): ") try: v3 = [] for i in range(len(v1)): v3.append(v1[i]*v2[i]) print v3 except IndexError: print "vectors/lists need to be equal in length!" A note: Please use code tags to enclose … | |
Re: You might want to start a new thread with the proper title. It will help you to get help! | |
Re: [quote=fonzali;310041]thanks , Ilooked at the code and it seems not so easy for me to digest but I will do my best , thanks again[/quote]If this is your first experience with GUI programming, it will take some time to digest. However, playing with labels, buttons, windows and mouse clicks is … | |
Re: If you Google "Convert C++ to Java", you get 1,770,000 hits with plenty of tools available in the first ten hits. If those tools are perfect in every case, I don't know. Take a look! | |
Re: Generally one would use Windows API function SetPixel(hDC, x, y, color). For an actual example see: [URL]http://www.daniweb.com/code/snippet217.html[/URL] | |
Re: Two nice solutions, wow! Now I have a question, what if we had a "[COLOR=#dd0000]-$245.99" to extract so it would give "-245.99"? [/COLOR] | |
Re: If you just want to tinker with GUI coding to get a feel for it, Tkinter is simpler to code. For real involved GUI development I would use wxPython. It has a large number of fancy widgets for grids, mulimedia (MP3, midi, avi, mpg, wav, au), image display (jpg, png, … | |
Re: This was quite a lively discussion! A question to ghostDog74, can you use regular expression to simply extract the number from each dataline, no matter what the non-numeric stuff is? | |
Re: You could write a small Python program that will run your script repeatedly (put a time delay into the loop) with arguments you give it ... [code=python]# run an external program from within Python code with # subprocess.call(["program-name", "arg1", "arg2", ...]) import subprocess # part of a loop subprocess.call(["C:/Python25/Python.exe", "MyScript.py", … | |
Re: I have done it on one of my machines at work, but with Windows you end up with some problems with file-type associations. You also might have to write a batch file to run DrPython with the correct version of Python. Some IDEs (I think its PyPE) allow you to … | |
Re: Python offers a number of modules providing easy file compression and decompression. Here are code snippets for two of the popular compression formats ... zipfile --> [URL]http://www.daniweb.com/code/snippet629.html[/URL] tarfile --> [URL]http://www.daniweb.com/code/snippet630.html[/URL] | |
Re: Looks like Ghostdog is right ... [code=Python]# test sample from user input months = ['Dec', 'Jan'] # test sample from os.path.walk() files = ['FebWork1,dat', 'JanWork3.dat', 'DecWork7.dat'] # test dates = [] for i in files: for j in months: if j in i: dates.append(i) break print dates # ... or … | |
![]() | Re: Write a small Python program like the one below and save it as PrintHello.py ... [code]print "Hello" raw_input("Press Enter to go on ... ") [/code] Now run this program ... [code]import subprocess subprocess.call(["Python.exe", "PrintHello.py"]) [/code]It seems to find Python.exe without any problems. ![]() |
I have read complaints about the limited types of files that can be attached to threads. This is a test to attached newer and better compression files past the silly .zip file extension limits. Note, remove the final .zip from this file ... | |
Re: One way to total up blackjack cards properly is presented in this thread: [URL]http://www.daniweb.com/techtalkforums/post298373-102.html[/URL] | |
Re: You need to download and install the Python Extensions for Windows: pywin32-210.win32-py2.5.exe free from: [URL]http://sourceforge.net/projects/pywin32/[/URL] This is a self-installing exe file, so all you need to do is doubclick the filename. | |
Re: One more time: Code tags are particularly important with Python code since they preserve the indentations. Without the proper indentations Python code becomes hard to read and understand! I will show the needed tags in reverse so they don't activate: at the end of your code add this tag /code … | |
Re: Code tags are particularly important with Python code since they preserve the indentations. Without the proper indentations Python code becomes hard to read and understand! I will show the needed tags in reverse so they don't activate: at the end of your code add this tag /CODE at the start … | |
Re: Code tags are particularly important with Python code since they preserve the indentations. Without the proper indentations Python code becomes hard to read and understand! I will show the needed tags in reverse so they don't activate: at the end of your code add this tag (/code) at the start … | |
Re: There is a product out there called Movable Python for USB Flash Cards. Used to be freeware, but has turned commercial (costs just a few pounds) as of dec2005. Also known as "Python On a Stick" (it is for windows only!) ... [URL]http://www.voidspace.org.uk/python/movpy/index.html[/URL] [URL]http://sourceforge.net/projects/movpy[/URL] | |
Re: Calculate the frequency needed to fuse ammonia to oxygen and helium in a "Phaseshift Quartz Capillary Cold Fusion Reactor". Seriously, here are three projects that might be worthwhile: 1) Write a simple Python code to C++ code converter. 2) Write a small Python Expert System 3) Write a Python program … | |
Re: Have you taken a good look at BoostPython? [URL]http://wiki.python.org/moin/boost%2epython[/URL] Boost works much smoother with Python then the old Swig approach. You could also use Jython. Jython has Python syntax but works very well with Java. It compiles to JVM bytecode rather then PVM bytecode and can use the Java library … | |
Re: I have used HapDebugger, Boa, PyScripter, IDLE, SPE and PythonWin, but always come back to DrPython. DrPython is still an active project and just a very pleasant IDE to use. Very easy on the disk space. I also use a more general editor/IDE called ConText. That one allows me to … | |
Re: [quote=sneekula;298826]I know that one has to be careful with mutable arguments like lists applied to function calls, so that things like this won't accidentally happen: [php]def add_item(list2): list2.append(99) return list2 list1 = [1, 2, 3] list3 = add_item(list1) print list1 # [1, 2, 3, 99] oops! print list3 # [1, … | |
Re: Note that GPA is the average of the GP you enter, take a look ... [code=python]print "The grade point average (GPA) calculator:" def get_list(prompt): """ loops until acceptable data or q (quit) is given returns a list of the entered data """ data_list = [] while True: sin = raw_input(prompt) … | |
Re: If a sort would be purely by ASCII value then you would have to treat the list elements as strings ... [code=python]# convert all list items to type string ... mixed_list = [11, 'Dick', 12, 'Mary', 7, 'Zoe', 9, 700, 777, 'Paul', 13456789] str_list = [str(x) for x in mixed_list] … | |
Re: You can flatten the list, might call this un-nesting and then search ... [code=python]def xflatten(seq): """a generator to flatten a nested list""" for x in seq: if type(x) is list: for y in xflatten(x): yield y else: yield x nested_list = [1 ,'Dick', 2, ['Mary', 7, 9, [700, 777, 'Paul']], … | |
Re: Binding the mouse button to a particular function will do it ... [code=python]from Tkinter import * def left(event): root.title('clicked left') btn1.config(fg='blue') def right(event): root.title('clicked right') btn1.config(fg='red') root = Tk() root.title('click left or right on button') btn1 = Button(root, text=' Click on me ... ', width=40) btn1.pack() btn1.bind('<Button-1>', left) # bind … | |
Re: If you like to practice with list comprehension, you can use this ... [code=python]def swap_dictionary(original_dict): return dict([(v, k) for (k, v) in original_dict.iteritems()]) [/code] | |
Re: The return statement will not only break out of the while loop but also out of function main()!! If you enter data in a loop you need to accumulate the entries in some fashion. | |
Re: I played with the code for a while and made these observations and corrections ... [code=python]# save as p2sort.py from p2gpa import Student, makeStudent def readStudents(filename): infile = open(filename, 'r') students = [] for line in infile: students.append(makeStudent(line)) infile.close() return students def writeStudents(students, filename): outfile = open(filename, 'w') for s … | |
Re: [QUOTE=sneekula;295783]Thanks mawe, that works well. Just a question, if get rid of the titlebar, how can I exit the program?[/QUOTE] You need to at Exit to your menu or add an exit button. | |
Re: There were a number of errors in your code, please read my comments carefully. I just made the program work, that's all ... [code=python]#Bus Ticket.py """A program that generates bus tickets based on data input by the user""" from Tkinter import * global passPrice global passType global start global end … | |
Re: You could simply add something like line btn1.configure(state=DISABLED) into your show_image2 function. | |
Re: A function calling itself, or recursion, is like a loop. As with any loop you have to give it an exit condition, or it will keep going. So, watch out that your test print statements don't ruin your exit condition or call the function itself. Just out of curiosity I … | |
| |
Re: This will not work because list a and b are not the same length ... [php]a = [1, 2] b = [2, 3, 6, 1] # this will not work here ... if sorted(a) == sorted(b): print 'a is in b' else: print 'a is not in b' [/php] Using … | |
Re: A oscillating quarz capillary cold fusion reactor and 29.3 mg of tritiated ammonia to keep the thing working for the next ten years. | |
Re: I like to use PyInstall for Tkinter files. The result looks a little neater than the Py2exe result. I made up this small help file a while ago ... [QUOTE]Extract the pyinstaller_1.3.zip file into eg. C:\Python24 and rename the new directory to C:\Python24\PyInstaller13\ (to make it easier on the eye). … | |
Re: Jeff, I trust you have taken a look at: [url]http://www.daniweb.com/techtalkforums/post257347-78.html[/url] I had a similar problem there and solved it. Other articles mention that sometimes you have to protect Tkinter stored images from garbage collection. That may be with earlier versions of Python. To rotate an image you best use the … | |
Re: Most of us don't have a chinese character set on the PC, so help might be in the distance. | |
Re: I made some corrections to your program, please read the comments ... [code]#Filename: address.py import pickle address = {} def print_menu(): print 'Address Book' print print '1. Print contacts' print '2. Add contact' print '3. Delete contact' print '4. Alter contact' print '5. Save contacts' print '6. Load contacts' print … |
The End.