Forum: Python 2 Days Ago |
| Replies: 3 Views: 144 Which version of Python are you using?
Using Python2 you would use something like this to create an array of names. Generally Python uses lists for arrays.
# create the name list
name_list = []... |
Forum: Python 5 Days Ago |
| Replies: 4 Views: 195 Don't forget to set a and b to zero outside the loop. |
Forum: Python 5 Days Ago |
| Replies: 5 Views: 203 You might want to use bind() rather then the command arg. Take a look at:
http://www.daniweb.com/forums/post1077620.html#post1077620 |
Forum: Python 5 Days Ago |
| Replies: 80 Views: 18,026 Using the Tkinter GUI toolkit, the question of how to detect which button has been clicked comes up often. There are several solutions. The first solution is to use the bind() method that passes an... |
Forum: Python 10 Days Ago |
| Replies: 8 Views: 310 In all fairness to snippsat, he did point out that DaniWeb contains a fair number of well commented PyQT examples to study and experiment with.
As of 08dec2009 we have:
Mainwindow frame ...... |
Forum: Python 12 Days Ago |
| Replies: 1 Views: 308 This simple code shows how to write text with a given font, font size and color using the module pygame ... |
Forum: Python 12 Days Ago |
| Replies: 130 Views: 50,264 This code shows you how to create a drawing on a wxPython canvas and save the drawing to a standard image file ...
# use a drawing bitmap and wx.MemoryDC to create a canvas you can
# draw on and... |
Forum: Python 15 Days Ago |
| Replies: 2 Views: 347 Hide the root window with:
root.withdraw()
Bring the root window back up with:
root.update()
root.deiconify()
Remove root window border and title bar with:
root.overrideredirect(True) |
Forum: Python 18 Days Ago |
| Replies: 4 Views: 435 This program uses the Python win32 extension module to get information on disk or flash drives for Windows machines. Specify the drive with its letter. If no drive letter is specified, the current... |
Forum: Python 19 Days Ago |
| Replies: 3 Views: 215 Take a look at this recent thread:
http://www.daniweb.com/forums/thread241860.html
were we discussed functions and parameter passing. |
Forum: Python 19 Days Ago |
| Replies: 14 Views: 488 Tkinter is Python's wrapper of the GUI toolkit Tk, originally written in a computer language called TCL. Tkinter has the advantage of a small footprint, also IDLE, the IDE that ships with Python, is... |
Forum: Python 19 Days Ago |
| Replies: 14 Views: 488 Don't overlook the fact that the Python installer you use is specific for the Operating System. If you install Python on a Windows OS, the GUI toolkits will use the Windows GUI. A similar thing... |
Forum: Python 20 Days Ago |
| Replies: 9 Views: 456 You pass variables as need as function arguments and/or returns. |
Forum: Python 21 Days Ago |
| Replies: 9 Views: 456 Here is a rather simple example of a number of functions working together from:
http://www.daniweb.com/forums/post104853.html#post104853
def get_name():
"""this function only returns... |
Forum: Python 21 Days Ago |
| Replies: 7 Views: 438 The function main() can be simplified ...
def main():
while True:
fahrenheit2celsius()
cont = raw_input('Continue converting? (yes/no): ')
if 'n' in cont.lower():
... |
Forum: Python 22 Days Ago |
| Replies: 2 Views: 212 use temp = self.set_greyLevel(grayScale) |
Forum: Python 23 Days Ago |
| Replies: 13 Views: 437 I tend to agree with Gribouillis. As your program grows you can split out some classes in a linear fashion. Later on, as the bugs are worked out, turn them into modules |
Forum: Python 25 Days Ago |
| Replies: 9 Views: 513 I tried the latest version of Eric (4.3.9). It assiste with PyQT syntax, but does not accept the newer connect style used with PyQT 4.5+. Somewhat irritating! |
Forum: Python 26 Days Ago |
| Replies: 2 Views: 243 __str__() does operator overloading in a class and "hijacks" str() in any class instance operation that uses str(). So print crit1 will use it, because it uses str() to make it printable. Whereas... |
Forum: Python 27 Days Ago |
| Replies: 10 Views: 556 I assume the question is:
Who is foolish enough to do my homework for me? |
Forum: Python 28 Days Ago |
| Replies: 6 Views: 316 When you use a.extend(b) or a.sort() then list a is changed, since both are inplace functions. Also when you pass a list to a function argument, be aware that the list is a mutable object and... |
Forum: Python 33 Days Ago |
| Replies: 5 Views: 289 Why don't you just run the sample code I gave you with the image_file = "mars.jpg" and make sure you have the image file in the working directory or give it the full path.
Avoid the crap you added... |
Forum: Python 33 Days Ago |
| Replies: 5 Views: 289 Pygame can load quite a number of image formats. Here is an example ...
# experiments with module pygame
# free from: http://www.pygame.org/
# load and display an image using pygame
import... |
Forum: Python 34 Days Ago |
| Replies: 9 Views: 342 Correct. Don't you admire the beauty of Python version changes? Right out of a Monty Python show!
Actually, most computer languages have had their fair share of version changes, they are always... |
Forum: Python 34 Days Ago |
| Replies: 6 Views: 319 You could do something simple like this ...
from graphics import *
import random
def drawCircle(win, centre, radius, colour):
circle = Circle(centre, radius)
circle.setFill(colour)
... |
Forum: Python Nov 13th, 2009 |
| Replies: 11 Views: 539 Back to the original code, this would have made more sense ...
class Player:
"""Enter name as string"""
def __init__(self, playername):
self.name = playername
def... |
Forum: Python Nov 11th, 2009 |
| Replies: 14 Views: 590 The nice thing about Xydric's approach is that it doesn't lose the important connectivity with the original dictionary via the keys ...
data = {
'1234': ['Matt', '2.5', 'CS'],
'1000': ['John',... |
Forum: Python Nov 10th, 2009 |
| Replies: 13 Views: 351 When you have a project like this, it is best to test each shape you want to draw before you combine it all. Let's start out with a pygame template that you can use for each shape ...
import pygame... |
Forum: Python Nov 10th, 2009 |
| Replies: 14 Views: 590 So you have a dictionary after all!
Dictionaries are indexed by key and the keys are in a hash order for fast lookups. They will always display in this order! If you want to sort by a certain... |
Forum: Python Nov 8th, 2009 |
| Replies: 1 Views: 411 This code snippet shows you how to sort more complicated objects like a list of lists (or tuples) by selecting an index of the item to sort by. |
Forum: Python Nov 8th, 2009 |
| Replies: 14 Views: 590 You can also use a somewhat older concept of sorting, the Schwartzian transform algorithm. This is made very easy with Python's list comprehension ...
# sort a more complex combination of... |
Forum: Python Nov 8th, 2009 |
| Replies: 14 Views: 590 Similar to Gribouillis' code, but uses lambda as a helper function ...
# sort a more complex combination of lists/tuples:
mylist = [
(1, ['a', '3.1', 'ad']),
(2, ['b', '4.0', 'bd']),
(3, ['c',... |
Forum: Python Nov 6th, 2009 |
| Replies: 4 Views: 259 You can use one of the built-in string functions ...
n = 2
digits = 3
ns = str(n).rjust(digits, '0')
print(ns) # 002 |
Forum: Python Nov 3rd, 2009 |
| Replies: 6 Views: 467 If
remove('an', 'banana') --> 'bana'
then this should be
remove('iss', 'Mississippi') --> 'Missippi'
So you can use ...
def remove(sub, s):
# replace first sub with empty string
return... |
Forum: Python Nov 1st, 2009 |
| Replies: 3 Views: 180 It can be as simple as this ...
import os
import time
# pick a file you have in the working directory
filename = "beachball.jpg"
# show file creation time
print(... |
Forum: Python Oct 31st, 2009 |
| Replies: 2 Views: 451 Take a look at:
http://www.daniweb.com/forums/post1032475.html#post1032475 |
Forum: Python Oct 31st, 2009 |
| Replies: 80 Views: 18,026 The Text widget of the Tkinter GUI toolkit is the start of a simple text editor. Here we explore how to get the line (row) and column numbers of the text insertion point ...
# explore Tkinter's... |
Forum: Python Oct 27th, 2009 |
| Replies: 5 Views: 398 The best way to learn any computer language is to experiment with the concepts of the language, and if you are stuck, search the manuals and ask question on a language forum like this. |
Forum: Python Oct 27th, 2009 |
| Replies: 130 Views: 50,264 Its time to explore wxPython's wx.Timer() and wx.StopWatch() widgets. The stopwatch works in the background to track the length of a process ...
# explore wxPython
# wx.Timer() one_shot and... |
Forum: Python Oct 26th, 2009 |
| Replies: 17 Views: 527 Check the spelling of getPos() |