1,175 Posted Topics
Re: 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 = … | |
Re: First of all, let us know which GUI toolkit you are using and give us some of your pertinent code. | |
Re: 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") … | |
Re: Put in a few test print() to catch the many errors. | |
Re: line 15 **return estimate** should be outside the loop | |
Re: You could use the approach shown in this code snippet: http://www.daniweb.com/software-development/python/code/216591/area-unit-conversion-python | |
Re: So, where is the right post? | |
Re: The speed of reading and writing huge files is limited by your hardware. | |
Re: **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 | |
Re: 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] … | |
| |
Re: 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) … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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) | |
Re: You can also use an online Python IDE: http://www.daniweb.com/software-development/python/threads/20774/starting-python/17#post1887125 | |
Re: Crazy Horse the great leader and warrior of the Teton Sioux. | |
Re: I think Z is applying this to a Windows batch command. | |
Re: 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 … | |
Re: Write a letter to your government to outlaw boredom! In other words, get involved in politics and you never get bored. | |
Re: Windows note: control panel>System>Advanced>Environment Variable allows you to add PYTHONPATH + directories used | |
Re: This will do stuff if x is **not** zero, False, None or empty if x: do stuff | |
Re: 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. | |
Re: "unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep" - my daily unix commands | |
Just wondered which computer language is best suited for preteen students. Any ideas or experiences? | |
Re: 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. | |
Re: 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 … | |
Re: I use LiquidIcon free from: [url]http://www.softpedia.com/get/Desktop-Enhancements/Icons-Related/LiquidIcon-XP.shtml[/url] | |
Re: [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? | |
Re: 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, … | |
Re: You can also work on a novel and let Python write it. | |
Re: 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] | |
Re: 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. | |
Re: kiddo might have to use a thread and a hook to the keyboard to get tis to go | |
Re: 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. | |
I need a function that returns True or False if an integer n is a prime. Any 'high speed' thoughts? | |
Re: 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 … | |
Re: [QUOTE=jephthah;887462]wtf? where is Lynx?[/QUOTE]What is Lynx? | |
Re: "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! | |
... this is your favorite pickup line: "Hey sweets, does this rag smell like chloroform? " | |
Is there a way to read Adobe PDF files with Python? | |
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? | |
Re: 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! | |
Re: I like avatars that say something about the owner. | |
The End.