4,305 Posted Topics
Do I have to spell it out for you? This short C code will do just that. It will spell out an integer number in English words. The banks do that on large checks, and it would be nice to get one of those every now and then. | |
Re: [QUOTE=Garrett85;1298807]... In the above code, what on earth is the little underscore doing in that for loop? for _ ...[/QUOTE]The underscore is a variable name Python uses internally. Someone is trying to be a show-off! IMHO, those things lead to unnecessary confusion. BTW, where are you copying this dated pygame … | |
Re: My advice, learn C++ When you learn C++ you also learn C, Java and C# to a fair extent, since they are so closely related. Sort of like classical English at Harvard and street English in certain parts of LA. C# is the new kid on the block (2000) and … | |
Re: If you run your Python code from the shell, you will most likely not be in the same directory as your file word.txt Give this a try to show the current working directory the shell looks at ... [code]>>> import os; os.getcwd() 'C:\\Python26' >>> [/code]Also, if you use Unix, file … | |
Re: I went to a fight the other night and a hockey game broke out. (one of Rodney Dangerfield's lines) | |
Re: Here is an example that works ... [code]# create a frame class containing two panel classes import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize) self.panel1 = MyPanel1(self) self.panel2 = MyPanel2(self) sizer = wx.BoxSizer() sizer.Add(self.panel1, proportion=1, flag=wx.EXPAND) sizer.Add(self.panel2, proportion=1, flag=wx.EXPAND) self.SetSizer(sizer) class MyPanel1(wx.Panel): def __init__(self, … | |
Re: 1) I believe if a deal sounds too good, it is most likely a scam. 2) Full moon nights bring out the crazies. 3) There is no such thing as an honest politician. 4) When you die you lose your senses. | |
Re: Input the two numbers as a string split the string into a two item list check if each item is a valid number then use the index to get at each numeric item convert each number with float() Here is a little function to check if a string is numeric … | |
Re: TOSHIBA and DELL Good quality in both cases. Had tough luck with HP. | |
Re: Some more insight ... [code]import copy import pprint def funk(): """ wrote class inside function to keep local dictionary vars() clean """ class C: pass bob = C() joe = C() pprint.pprint(vars()) print('-'*50) # make a copy of vars() to freeze it vars_frozen = copy.copy(vars()) for key in vars_frozen: if … | |
Re: Lines read from a text file are strings, so even something as simple as this will work ... [code]# a simple wxPython template for testing widgets '''-->my_file.txt x a b ''' import wx app = wx.App(0) frame = wx.Frame(None, wx.ID_ANY, size=(300, 200)) panel = wx.Panel(frame, wx.ID_ANY, size=(300, 200)) #text_label = … | |
Re: Not quite as arduous if you use a template approach, then you only need to customize a few things to fit your task. Here is an example of a general Tkinter template that ask for two numbers (tk.Entry), processes them and displays the result (tk.Label) ... [code]# a general Tkinter … | |
Re: You can accomplish your module task by first creating the file commonModules.py [code]# save as commonModules.py def makeName(): name = raw_input("Please enter your name: ") return name def makeAge(): year = input("What is the current year? ") byear = input("What year were you born in? ") age = year - … | |
Re: You do it simply along the line of this calculator key pad example ... [code]# create a calculator key pad with Tkinter # tested with Python 3.1.2 and Python 2.6.5 # vegaseat try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk # needs Python25 … | |
Re: Your problem is not with app.destroy(), but with track.stop() self.track is an instance name (instance of pygame Sound class) in class SoundPanel and needs to be associated with the proper instance of class SoundPanel like panel1.track.stop(), panel2.track.stop() etc. I took the liberty to play around with your previous program (nice … | |
Re: Most GUI toolkits have a keyboard option for a button, implemented by the '&' character. So, if your button label is "E&xit", only "Exit" shows on the button. However pressing alt/x on the keyboard will activate the button too. You may not be able to display the '&' on a … | |
Re: You are making your life too complicated! You are almost there actually ... [code]def convertToSeconds(hours, minutes, seconds): "Convert time to seconds." return hours * 3600 + minutes * 60 + seconds # give time as a (hours, minutes, seconds) tuple time1 = (8, 30, 0) time2 = (9, 36, 40) … | |
Re: The problem with Python when you come from C++ is that Python code is just mind-numbingly simple ... [code]def make_square(side): for k in range(side): print('*' * side) make_square(4) [/code] | |
Re: One error I can see in line 19 of the module ... [B]to 1.0,[/B] should be [B]to = 1.0,[/B] | |
Re: What version of Python are you using? | |
Re: [B]value_list = ['12345'][/B] Here you have a list of one item, you want the item at index zero [B]value_str = value_list[0][/B] | |
Re: Just some advice: When you ask for help you got to be humble. You can't force it! Show us some effort! While you are waiting for an answer, google. There are a lot of these screensaver codes out there. | |
Re: I downloaded PyQt-Py2.5-gpl-4.4.2-1.exe from [url]http://www.riverbankcomputing.co.uk/software/pyqt/download[/url] This binary Windows installer installs well on Windows XP and contains everything you need to use the PyQt GUI toolkit. I downloaded and tried the Eric IDE with it, and it seems to work by simply double clicking on the file Eric.pyw However, I am … | |
The code is shamefully short, but here it is. Now you can listen to the many sound files in wave (.wav) format and boing, chirp, chime, bark, booh, laugh and mooh at the people around you. | |
Re: [QUOTE=Ancient Dragon;1159987][url]http://www.youtube.com/watch?v=LCAdotyM-Eo[/url] Warning: contains GF violence.[/QUOTE]Well, she must have some other redeeming features. Maybe she can cook! | |
Re: You may also want to look at Henri Bumsfeld's Prime Number Function Improvements (Python) at: [url]http://www.daniweb.com/code/snippet216871.html[/url] | |
Re: The pygame.mixer is a required argument in function [B]create_gui(app, mixer, sound_file)[/B] where it is used in code line [B]track = mixer.Sound(sound_file)[/B] | |
Re: You would be better off to post that on the DaniWeb C Forum. | |
Re: You are better off using a list of class instances. Python arrays, like C arrays are meant to hold only very limited basic types. | |
Re: Take a look at: [url]http://effbot.org/tkinterbook/tkinter-dialog-windows.htm[/url] | |
Re: The first thing that sticks out like a sore thumb is that you are using tabs for indentations. It makes for ugly and troublesome code. Use the standard 4 spaces for indents like most people do. | |
Re: [QUOTE=abcdr;1285819]nevermind. I got it. here's what I did: [code] def wordReverse(word): acum = "" for ch in word: acum= ((ch)+"\n") + acum print acum [/code][/QUOTE]Great, very nice solution! You can use Python built-in functions to simplify it a little ... [code]def wordReverse(word): for ch in reversed(word): print ch wordReverse("python") [/code] | |
Re: [QUOTE=kate2mba;1285854]... My exercise says: Write a function wordPop that accepts a text and a length N and returns the list of all the words that are N letters long, sorted by their length. ... [/QUOTE]According to this, the function has to return only words with the length N, so what … | |
Re: Here would be simple example ... [code]# explore wxPython wx.Frame with # a wx.TextCtrl to enter some text # a wx.Button to start process action # a wx.StaticText to display the result import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle): wx.Frame.__init__(self, parent, -1, mytitle) self.SetBackgroundColour("yellow") # create some widgets self.edit … | |
Re: 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) Bring the border and title bar back after 5000 milliseconds: root.after(5000, root.overrideredirect, False) | |
Re: Python31 includes the Tkinter Tile extension module ttk. Ttk comes with 17 widgets, 11 of which already exist in Tkinter: Button, Checkbutton, Entry, Frame, Label, LabelFrame, Menubutton, PanedWindow, Radiobutton, Scale and Scrollbar The 6 new widget classes are: Combobox, Notebook, Progressbar, Separator, Sizegrip and Treeview You have to do some … | |
Re: Python2 seems to take care of empty lines Python3 needs newline='\n', for instance ... [B]reader = csv.reader(open("some.csv", newline='\n'))[/B] | |
Re: It is simply the effect of entropy on humanity as a whole. Or you might say: [QUOTE]God loves dumb people because He mad so many of them![/QUOTE] | |
Re: There is a slightly more advanced example here: [url]http://www.daniweb.com/forums/post1282201.html#post1282201[/url] | |
Re: In [B]threeRect = vl.get_rect()[/B] where does v1 come from? | |
Re: [QUOTE=tonyjv;1273744]Like this seems to work, but I do not know if it is easiest. If you use Python 3, surely there must be cleaner alternative using dictionary comprehensions. [CODE]import operator d1 = dict() d1[0] = 1 d1[1] = 2 d1[2] = 2 maxValue = max(d1) print [key for key in … | |
Re: Tkinter is remarkably tolerant, you can use or leave off app in the Scale or Checkbutton widgets. Since there is only one parent, Tkinter figures it out. It is a good habit to put the parent in, just in case there is more than one. | |
Re: Here is one way to do this using a list of lists ... [code]# example data string obtained from open('test.txt', 'r').read() data_str = """\ My name is x. I am 45 years old. My girlfriends name is y. She is way too old for me. y wears weird clothes. Good … | |
Re: You have to use PIL and Tkinter together. See this blog on the PIL transparency: [url]http://nadiana.com/pil-tutorial-how-create-button-generator[/url] | |
Re: Maybe this shows you how to package a console program ... [code]""" con_setup.exe Using cx_freeze with Python31 to package a console program to an executable file (.exe in Windows OS). Might want to put a console-wait-line in at the end of your program. Put this setup program and your console … | |
![]() | Re: My hunch, do not install the 64bit version of Python, use the 32bit version. Otherwise, many external modules will not install properly. ![]() |
Re: Just some quick observations: 1) replace recursion with a while loop 2) the way you calculate blah, it will always be that last calculated line [B]blah = cos(radians(x)*9)[/B] 3) don't use math for a function name since it is a module name in Python this will bite you sooner or … | |
Re: If you write a program that needs to load an image file, it is easiest to simply stick a copy of the image file into the same folder that the program works out of. |
The End.