1,175 Posted Topics

Member Avatar for Yzk
Member Avatar for slasel

To pass an argument in the button command use lambda: try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def click(s): """called with lambda""" if s == "one": root.title("Button one has been clicked") else: root.title("Button two has been clicked") root = tk.Tk() b1 = …

Member Avatar for slasel
0
286
Member Avatar for slasel

First of all, let us know which GUI toolkit you are using and give us some of your pertinent code.

Member Avatar for slasel
-1
79
Member Avatar for biancairis93

You could also use a list of instances of class Persons like shown in the example here: # format: ni_number firstname lastname age data_str = '''\ 55512 Bart Simpson 45 45622 John Smith 58 46231 Alicia Sands 27 ''' fname = "data123.txt" # write test data file with open(fname, "w") …

Member Avatar for Lardmeister
0
127
Member Avatar for june.pierre.311
Member Avatar for siaosituimoloaublood
Member Avatar for TrustyTony
0
5K
Member Avatar for tizzqman

You could use the approach shown in this code snippet: http://www.daniweb.com/software-development/python/code/216591/area-unit-conversion-python

Member Avatar for sneekula
0
232
Member Avatar for mical700
Member Avatar for bintony.ma_1
Member Avatar for sym366

**from connect4cell2 import Connect4Cells** make sure the file you are importing is saved as connect4cell2.py **self.cells = Connect4Cells(rows, columns, 3)** self.cells can now use any of the instances methods like row_flag = self.cells.checkRow(rowIndex) you have to supply the rowIndex value

Member Avatar for sym366
0
1K
Member Avatar for flopoe

You can insert a print statement for testing the progress, and see how the higher values bubble to the end and lower values bubble to the start of the list: myList=[43,21,12,80,3,2,35] print(myList) print('-'*30) end = len(myList)-1 while (end != -1): swapped = -1 for i in range(0, end): if myList[i] …

Member Avatar for vegaseat
1
984
Member Avatar for inaxassan
Member Avatar for inaxassan

At this point you may want to actually study up on Python classes, you are making some major mistakes. class Schedule: def __init__(self, course, points, level): self.course= course self.points = points self.level = level def get_course(self): return self.course # create instances # Schedule(course, points, level) sched1 = Schedule("Programming101", 4, 1) …

Member Avatar for vegaseat
-1
756
Member Avatar for inaxassan

Your input to the class is your sentence/text, so put that into the class constructor `__init__()` as a parameter after self. Note that by convention class names are capitalized, it makes code much more readable: class Sentence: def __init__(self, text): self.text = text def get_first_word (self): word_list = self.text.split() return …

Member Avatar for sneekula
0
1K
Member Avatar for inaxassan

Example: class AirlineTicket: # by convention capitalize class names def __init__(self, name, orig, dest, travel_date, travel_class, price): # assign parameters to the instance self self.name = name self.origination = orig self.destination = dest self.travel_date = travel_date self.travel_class = travel_class self.price = price def info(self): # format the info string info_str …

Member Avatar for sneekula
-1
2K
Member Avatar for krystosan

Let's give it a try: import sys from PyQt4.QtCore import * from PyQt4.QtGui import * app = QApplication(sys.argv) # ----- start your widget test code ---- # create the label label = QLabel() label.show() # insert a text string label.setText('Hello fron DaniWeb!') print(sys.argv) # ---- end of widget test code …

Member Avatar for Gribouillis
0
2K
Member Avatar for hisan

A helper function will do: '''sort_alpha_only1.py sort only the alphabetic part of a word has: ['test1_two', 'testOne', 'testTwo', 'test_one'] wants: ['testOne', 'test_one', 'test1_two', 'testTwo'] ''' def alpha_only(word): ''' helper function to sort only the alphabetic part of a word ''' word = "".join(c for c in word if c.isalpha()) return …

Member Avatar for sneekula
0
519
Member Avatar for stevthym

You mean something like this: mylist = [] for c1 in range(65, 90): for c2 in range(65, 90): mylist.append((c1<<16) + (c2<<8) + 32) print(mylist) Or this: import array myarray = array.array('I', []) for c1 in range(65, 90): for c2 in range(65, 90): myarray.append((c1<<16) + (c2<<8) + 32) print(myarray)

Member Avatar for sneekula
0
221
Member Avatar for BigPaw

You can also use an online Python IDE: http://www.daniweb.com/software-development/python/threads/20774/starting-python/17#post1887125

Member Avatar for Lardmeister
0
270
Member Avatar for GrimJack
Member Avatar for GrimJack
3
534
Member Avatar for sasdap
Member Avatar for keyoh

Well, you could do something like this: [code=python]# File_lister2.py # create a list of all the files and sizes in a given direcory # and optionally any of its subdirectories (Python2 & Python3) # snee import os def file_lister(directory, subs=False): """ returns a list of (size, full_name) tuples of all …

Member Avatar for The Geek Scope
0
5K
Member Avatar for PrimeOutsourcin

Write a letter to your government to outlaw boredom! In other words, get involved in politics and you never get bored.

Member Avatar for Ene Uran
0
232
Member Avatar for GrimJack
Member Avatar for sandorlev

Windows note: control panel>System>Advanced>Environment Variable allows you to add PYTHONPATH + directories used

Member Avatar for Gribouillis
0
255
Member Avatar for hughesadam_87
Member Avatar for sneekula
0
99
Member Avatar for sillyboy

Listening to the finacial news and it makes me gag! You can now own all of General Motors for less than a Billion Dollars. By year's end GM, Chrysler and Ford may not exist any longer! Better switch to a classical FM station and a glass of wine.

Member Avatar for Helianthus
0
5K
Member Avatar for avgprogramerjoe
Member Avatar for WolfShield

"unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep" - my daily unix commands

Member Avatar for itzarun
0
1K
Member Avatar for sneekula

Just wondered which computer language is best suited for preteen students. Any ideas or experiences?

Member Avatar for Sanchixx
0
482
Member Avatar for mozart_azul

Visual Python Tkinter IDE is a very badly written piece of software with lots of errors. I don't recommend using it unless you want to waste a lot of time.

Member Avatar for mozart_azul
0
925
Member Avatar for KY_Fan

This is really a question of what version of Python you are using. If you use Python2 then input() is for numeric input, but with Python3 you will get strings. With Python27 this will work: # Python27 def main(): print("Adding:") a = input("Please select a number:") b = input("And another …

Member Avatar for sneekula
0
201
Member Avatar for Stefano Mtangoo

I use LiquidIcon free from: [url]http://www.softpedia.com/get/Desktop-Enhancements/Icons-Related/LiquidIcon-XP.shtml[/url]

Member Avatar for jsdevel
0
165
Member Avatar for srk619

[QUOTE=srk619;835650]ok i have added the 4 spaces and no errors displayed but three dots come ... so shall i add the rest of the code provide or was it going to print it all automatically[/QUOTE]Three dots? Are you using the Python shell?

Member Avatar for HiHe
0
657
Member Avatar for jcmeyer

jcmeyer, could you do me a favor and test this in your code, it makes things a lot more readable, and may avoid errors like you exerienced: [code=python]cur_ex = """ INSERT INTO DatabaseName (C1, C2, C3, C4, C5) SELECT ?, C2, C3, C4, C5 FROM DatabaseName WHERE C1=? """ self.cursor.execute(cur_ex, …

Member Avatar for webstart
0
222
Member Avatar for ckugblenu
Member Avatar for hughesadam_87

You can also use Python's built-in % format specifiers: [code]for outer in range(1,13): print '\t'.join("%5d"%(outer*inner) for inner in range(1, 13)) [/code]

Member Avatar for hughesadam_87
0
121
Member Avatar for ngurjar

Developing with Python will be simpler and faster, however the product might be slower. There is a spellchecker module for Python and a couple of GUI tool-kits.

Member Avatar for sneekula
0
144
Member Avatar for kiddo39
Member Avatar for jeugtsy
0
669
Member Avatar for Kippstah

When you use [B][COLOR="Red"]os.system('cls')[/COLOR][/B] you limit yourself to the Windows OS. In 99.9% percent of console apps you really don't need to clear the console screen.

Member Avatar for Beat_Slayer
-2
239
Member Avatar for sneekula

I need a function that returns True or False if an integer n is a prime. Any 'high speed' thoughts?

Member Avatar for wallars
0
1K
Member Avatar for rysin

You can use the Tkinter GUI toolkit too: [code=python]# KeyLogger.py # show a character key when pressed without using Enter key # hide the Tkinter GUI window, only console shows import Tkinter as tk def key(event): if event.keysym == 'Escape': root.destroy() print event.char root = tk.Tk() print "Press a key …

Member Avatar for TrustyTony
0
548
Member Avatar for adkool
Member Avatar for crunchie
2
896
Member Avatar for royng

"The Man With The Golden Gun" starring Roger Moore as James Bond (007). I like most of the 007 movies. James Bond is my hero!

Member Avatar for Netcode
0
389
Member Avatar for sneekula

... this is your favorite pickup line: "Hey sweets, does this rag smell like chloroform? "

Member Avatar for Netcode
0
674
Member Avatar for sneekula
Member Avatar for sneekula

I need to read in a text file, replace selected words and write the changed text back out to a file. Is there an easy way with Python?

Member Avatar for halamas
0
20K
Member Avatar for jml101

You are commiting one of the cardinal violations in Python when you mix tabs and spaces in your indentations. Many editors do not match the correct amount of spaces with your tabs, now you have a mess on your hand. Please use the customary 4 spaces only, avoid tabs!

Member Avatar for vegaseat
0
721
Member Avatar for Salem
Member Avatar for WolfShield

The End.