4,305 Posted Topics

Member Avatar for mattyd

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') # …

Member Avatar for mattyd
0
3K
Member Avatar for Aia

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.

Member Avatar for Aia
0
276
Member Avatar for Rickenbacker360

[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!

Member Avatar for vegaseat
0
230
Member Avatar for AussieCannon

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), …

Member Avatar for vegaseat
0
443
Member Avatar for vijay.neo

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.

Member Avatar for vegaseat
0
84
Member Avatar for defience

For things like that you better use: subprocess.Popen() For an example see: [URL]http://www.daniweb.com/techtalkforums/post197119-52.html[/URL]

Member Avatar for vegaseat
0
158
Member Avatar for defience

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]) …

Member Avatar for defience
0
127
Member Avatar for Shark7

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 …

Member Avatar for Shark7
0
355
Member Avatar for chris99

You might want to start a new thread with the proper title. It will help you to get help!

Member Avatar for bumsfeld
0
139
Member Avatar for fonzali

[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 …

Member Avatar for vegaseat
0
4K
Member Avatar for sandeepmuleymca

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!

Member Avatar for vegaseat
-1
109
Member Avatar for ankit_the_hawk

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]

Member Avatar for vegaseat
0
124
Member Avatar for bumsfeld

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]

Member Avatar for bumsfeld
0
1K
Member Avatar for sneekula

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, …

Member Avatar for sneekula
0
1K
Member Avatar for wandie

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?

Member Avatar for ghostdog74
0
161
Member Avatar for mattyd

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", …

Member Avatar for vegaseat
0
135
Member Avatar for sneekula

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 …

Member Avatar for vegaseat
0
114
Member Avatar for sneekula

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]

Member Avatar for vegaseat
0
136
Member Avatar for jrcagle

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 …

Member Avatar for jrcagle
0
140
Member Avatar for sharma_vivek82
Member Avatar for dams

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.

Member Avatar for dams
0
127
Member Avatar for vegaseat

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 ...

Member Avatar for KevinADC
0
55
Member Avatar for mattyd

One way to total up blackjack cards properly is presented in this thread: [URL]http://www.daniweb.com/techtalkforums/post298373-102.html[/URL]

Member Avatar for woooee
0
108
Member Avatar for goms

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.

Member Avatar for vegaseat
0
220
Member Avatar for sharma_vivek82

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 …

Member Avatar for vegaseat
0
447
Member Avatar for sharma_vivek82

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 …

Member Avatar for vegaseat
0
120
Member Avatar for sharma_vivek82

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 …

Member Avatar for vegaseat
0
125
Member Avatar for Matt Tacular

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]

Member Avatar for vegaseat
0
132
Member Avatar for Extremist

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 …

Member Avatar for jrcagle
0
329
Member Avatar for punithap

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 …

Member Avatar for vegaseat
0
127
Member Avatar for mattyd

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 …

Member Avatar for Ene Uran
0
200
Member Avatar for sneekula

[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, …

Member Avatar for jrcagle
0
230
Member Avatar for babutche

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) …

Member Avatar for babutche
0
1K
Member Avatar for sneekula

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] …

Member Avatar for vegaseat
0
3K
Member Avatar for sneekula

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']], …

Member Avatar for vegaseat
0
106
Member Avatar for sneekula

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 …

Member Avatar for vegaseat
0
8K
Member Avatar for sneekula

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]

Member Avatar for mawe
0
2K
Member Avatar for babutche

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.

Member Avatar for babutche
0
147
Member Avatar for babutche

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 …

Member Avatar for babutche
0
466
Member Avatar for sneekula

[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.

Member Avatar for sneekula
0
12K
Member Avatar for chris99

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 …

Member Avatar for chris99
0
1K
Member Avatar for mattyd

You could simply add something like line btn1.configure(state=DISABLED) into your show_image2 function.

Member Avatar for mawe
0
3K
Member Avatar for babutche

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 …

Member Avatar for woooee
0
109
Member Avatar for bud594
Member Avatar for Matt Tacular

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 …

Member Avatar for vegaseat
0
173
Member Avatar for roryt

A oscillating quarz capillary cold fusion reactor and 29.3 mg of tritiated ammonia to keep the thing working for the next ten years.

Member Avatar for roryt
0
168
Member Avatar for mattyd

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). …

Member Avatar for vegaseat
0
291
Member Avatar for jrcagle

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 …

Member Avatar for vegaseat
0
2K
Member Avatar for trihaitran

Most of us don't have a chinese character set on the PC, so help might be in the distance.

Member Avatar for vegaseat
0
162
Member Avatar for chris99

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 …

Member Avatar for vegaseat
0
133

The End.