4,305 Posted Topics
Re: Again, the simple rule of Python coding: import define main code Giving your code a common sense structure makes it easier to read and understand for people you are asking for help. | |
Re: You may want to modify something like that ... [code]# using the Zelle graphics module (derived from Tkinter) # http://mcsp.wartburg.edu/zelle/python/graphics.py from graphics import * def main(): w = 350 h = 250 win = GraphWin("Click to move shape (10 clicks max)", w, h) #shape = Rectangle(Point(200,200),Point(250,250)) shape = Circle(Point(100,100), 20) … | |
Re: Simple Python coding rules: import define main program flow Giving your code a common sense structure makes it easier to read and understand for people you are asking for help. Also, a few temporary test-prints will help you a lot here! | |
Re: You can use operator.itemgetter() as shown in this example ... [code]# count words in a text and show them by decreasing frequency # using operator.itemgetter() # collections.Counter() needs Python27 or Python3 import collections import operator # sample text for testing (could come from a text file) text = """\ If … | |
Re: The simplest way to rotate an image with the Tkinter GUI toolkit is to use the Python Image Library (PIL) rotate function. Check: [url]http://www.lfd.uci.edu/~gohlke/pythonlibs/[/url] to download PIL versions for Python27 and Python32 A simple example ... [code]from PIL import Image image = Image.open('Audi.jpg') # rotate 270 degrees counter-clockwise imRotate = … | |
Re: Why do you need to run configure.py and what do you expect to happen? | |
Re: The Singularity that was at the origin of the Big Bang was unmeasurable small. You could think of it as an unmeasurable small particle with an unmeasurable large temperature. Wonder how many those would fit into a cubic meter? | |
Re: Here is one way to do this ... [code]# list filenames with full path in a folder and its subfolders import os # use current folder or give a folder name folder = os.getcwd() for (paths, dirs, files) in os.walk(folder): for fname in files: full_name = os.path.join(paths, fname) print(full_name) # … | |
Re: Numpy arrays allow for numeric elements of a certain type only. Those can be integer, float or complex numbers. You can convert a Numpy array to a Python list ... [code]# using Python module numpy to create a multi-dimensional array/list import numpy as np # create a 2x3 array of … | |
Re: Go to: [url]http://pypi.python.org/pypi/pep8/0.4#downloads[/url] download: pep8-0.4.tar.gz extract contents into a temp folder using WinRAR.exe or alike find file pep8.py and copy it to a folder with your code Take a look at pep8.py with an editor, it has all the help built-in | |
Re: Hint, do not use tabs for indentations. It makes your code much harder to read. | |
Re: Since you don't have the Python Image Library (PIL) for C#, this task will be just about impossible. Also, this code uses block indentations of one space, very hard to read! | |
Re: Here is the classy way I prefer ... [code]# Tkinter with class (preferred template syntax) # create a label with font and color try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk class MyApp(tk.Tk): def __init__(self): # the root will be self tk.Tk.__init__(self) self.title("Lab … | |
Re: The problem with the wxPython GUI toolkit is that you are stuck using the old Python2 versions at this time. For a simple syntax comparison of four Python GUI toolkits see: [url]http://www.daniweb.com/software-development/python/threads/191210/866067#post866067[/url] With the advent of Python27 and Python31 (or higher) Tkinter has received an update with the ttk module, … | |
Re: A simple explanation of a Python class object ... [code]# a look at Python's class constructor, method and instance # class names are capitalized by convention to aid readability class Animal: def __init__(self, animal, sound): """ The constructor __init__() brings in external parameters when an instance of the class is … | |
Re: Pygame can handle quite a few different sound formats. There is also PyAudio. | |
The tkSnack sound module was developed at KTH in Stockholm, Sweden. A great module to generate sound, play and analyze sound files and speech. It was written using Tkinter and its native TCL language. Alas, the latest release is from 2005. However, the important file tkSnack.py can be converted to … | |
Re: Strange! Works fine with Python31, but not with Python32. You could be on to something! The egg-heads updated the str() function in Python32 to be more in line with the repr() function. | |
Re: Thanks Tony! I posted an example of PySide code at: [url]http://www.daniweb.com/software-development/python/threads/191210/1522002#post1522002[/url] | |
Re: The example in the Python32 docs elucidates that in earlier versions of Python here was a difference, the str() result was rounded off ... [code]import math print(repr(math.pi)) print(str(math.pi)) ''' result (Python31 and earlier) --> 3.141592653589793 3.14159265359 result (Python32) --> 3.141592653589793 3.141592653589793 ''' [/code] | |
Re: I assume you are using the Windows OS and Python 3.2, simply do this ... For PyQT download and run the Windows 32 bit self-extracting installer PyQt-Py3.2-x86-gpl-4.8.3-1.exe from [url]http://www.riverbankcomputing.co.uk/.../pyqt/download[/url] Py3.2 indicates that this the installer for Python 3.2, there are installers for other versions of Python too. You can copy, … | |
Re: [QUOTE=e-papa;1518448]Thanks for showing me something new, but how can i get the itertools, and then what are the things it does, is there a way i can get docs on it, please i really want to leard more.Is it built in with python.[/QUOTE] The Python module itertools is part of … | |
Re: This should be the stable release date of Python 3.2 final: February 19, 2011 Can you give us an example of which module gives you problems, and what is the error message? Also, avoid the 64bit version. There are plenty of third party modules that will only work with the … | |
Re: Kindly see: [url]http://www.daniweb.com/software-development/python/threads/355545/1519470#post1519470[/url] | |
Re: Nice try, but it will be too slow for large prime numbers. For instance try it with a large prime like 2147483647 You can speed things up a little realizing that all even numbers (except 2) are not primes. | |
Re: Study dentistry, those folks live off the pain of others. :) | |
Re: [B]When No Child Gets Ahead No Child Is Left Behind[/B] | |
Crypting with xor allows one to write one function that can encrypt and decrypt a file. In this example a text file is used, but it could be an image file as well. Once you have created the encrypted file you simply send it through the same function again to … | |
Re: e-papa's more exact download URL ... [url]http://sourceforge.net/projects/npppythonscript/[/url] | |
Re: Logic statements following the while are not always intuitive. I would code it this way ... [code]print("\nWould you like be X's or O's ? <O/X>:") human=["",""] while True: human[0]=raw_input("").upper() if human[0] == "X" or human[0] == "O": break print(human) # for test only [/code] | |
Re: Here is a simple way to accomplish transparency using the Tkinter GUI toolkit ... [code]# explore Tkinter transparency (simplified) try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk root = tk.Tk() # use opacity alpha values from 0.0 to 1.0 # opacity/tranparency applies to … | |
Re: [B]n = 1[/B] has to stay outside the for loop, or you would reset n all the time to 1 | |
Re: Floating point algorithms in all computer languages suffer from a small error as the floating point world meets the binary world. Representing -0.5 in just a sequence of 1 and 0 is not possible with true accuracy. Look at this ... [code]import math # use a list to show the … | |
Re: Well sort of ... [code]class myClass: def __init__(self, methodName): vars()[methodName] = "This is the result" self.__dict__ = vars() methodName = "myMethod" q = myClass(methodName) print( q.myMethod ) # This is the result [/code] | |
Re: If you use Python3, you can apply formatting this way ... [code]# needs Python3 data_list = [ (1, 'Dave'), (234, 'Einstein'), (100000, 'Bob') ] print("Printing out to file 'test123.txt' ...") fout = open("test123.txt", "w") for item in data_list: sf = "{0:>10d} {1:30}" # show on the screen as a test … | |
Re: Nice find! Of course you could look into subatomic particles and feel gigantic! | |
Re: I remember the days when restaurants used to serve chicken liver. Now most folks throw the stuff away. Actually, I feel sorry for the mechanic that has to do the separation. :) | |
Re: Ouch, mixing tabs and spaces really goofs up the code indentation. | |
Re: If fire fighters fight fires and crime fighters fight crime, what do freedom fighters fight? | |
Re: You are so close! Add a few test prints and things become more clear ... [code]'''assume test file Be.csv is: name2,number2;name3,number3;name1,number1 ''' fin = open("Be.csv") text_data = fin.read() fin.close() print(text_data) # test line_list = text_data.split(';') print(line_list) # test line_list.sort() print(line_list) # test fout = open("Ord.csv", "w") for line in line_list: … | |
| |
I am afraid, I am starting to like C#, despite the somewhat bloated .Net Framework requirements. Mister Bill's Microsoft is very supportive though. The language has a nice flow compared to GUI programming in C++. Here we are looking at a standard ListBox, add some items, sort them and select … | |
Mine without a doubt is Marilyn Monroe. [QUOTE]"It's not true that I had nothing on. I had the radio on."[/QUOTE] | |
Re: You can expand on something like this ... [code]''' ttk_multicolumn_listbox2.py Python31 includes the Tkinter Tile extension 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, … | |
Re: Why do cemeteries have fences around them? ni teg ot gniyd era elpoep esuaceb | |
Re: You can use something like this ... [code]# exploring the wxPython widget # wx.TextCtrl(parent, id, value, pos, size, style) # limit entry to numeric values with max 2 decimals import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, -1, mytitle, size=mysize) self.SetBackgroundColour("white") s = "Enter the price:" label … | |
![]() | Re: Let us all hope that this code is not from a Python book. |
Re: at the >>> prompt type the following: [COLOR=Green]execfile("script.py")[/COLOR] and press enter | |
Re: Here is an example how to do this with the Windows OS ... [code=python]# disable window title bar corner x click # you need to supply your own exit button from Tkinter import * def exit(): "dummy function" pass root = Tk() root.protocol("WM_DELETE_WINDOW", exit) btn_quit = Button( text="Quit", command=root.destroy ) … | |
Re: [QUOTE=frogboy77;1464573]How long does the average American football match last and what percentage of that time is actually play?[/QUOTE]Just think about all the time it took in ancient Rome to remove the dead bodies and severed parts from the Colosseum. ![]() |
The End.