904 Posted Topics
Re: You need to set gVar global in function setVar(), so it will be visible for function getVr(): [code=python]gVar = None def getVar(): return gVar def setVar(val): global gVar gVar = val [/code] | |
Re: The DOS command window is kind of stupid, you have to tell it in detail where every file is. | |
Re: I added some needed lines to your code, now it works. Somehow you have to refresh your drawing as you scroll: [code=python]import wx class Canvas(wx.ScrolledWindow): def __init__(self,parent): self.okno=parent self.radic = wx.FlexGridSizer(3,2,0,0) self.canvas = wx.ScrolledWindow(self.okno, -1) # EnableScrolling(bool x_scrolling, bool y_scrolling) self.canvas.EnableScrolling(True, True) # SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, # … | |
Re: So this will not work? [code=python]str1 = """line1 line2 line3 """ [/code] | |
Re: Must be something peculiar to the Mac OS, this code works fine on Windows: [code=python]import Tkinter as tk def change(event): root.title(str(v_red.get())) root = tk.Tk() # width x height + x_offset + y_offset (no spaces!) root.geometry("%dx%d+%d+%d" % (150, 120, 0, 0)) v_red = tk.IntVar() red = tk.Scale(root, label="Red", variable=v_red, from_=0, to=255) … | |
Re: Keyword variable image=object needs an object not a function call. You need to use image1=PhotoImage(file="image.gif") and then self.Button = Button(self, image=image1) | |
Re: Graphics.h? Let me guess, must be from the old Tubo C compiler (16bit), good luck to find anyone that uses this old bird! | |
Re: Here is the code for a title-free Tkinter window. [php]import Tkinter as tk root = tk.Tk() # eliminate the titlebar root.overrideredirect(1) # your code here ... root.mainloop() [/php]You have to exit the program somehow and could create one exit/quit button that needs secret password to quit. | |
Re: Sure Python has multidimensional arrays, they are called lists of lists or tuples of tuples etc. [code=python]mlist1 = [ [7, 12, 23], [22, 31, 9], [4, 17, 31]] print mlist1 # [[7, 12, 23], [22, 31, 9], [4, 17, 31]] # show list_item at index 1 print mlist1[1] # [22, … | |
Re: This uses popen4(), but I think its similar: [code=python]# run an external program (cmd) and retrieve its output: import os cmd = "ls" fin, fout = os.popen4(cmd) result = fout.read() print result [/code] | |
Re: RSC, thanks for the reference. Working with SWIG can be interesting, but their seems to be lots of pitfalls to avoid! | |
Re: For button1 use : [INLINECODE]self.myboxsizer.Add(self.button1,0,wx.EXPAND|wx.ALL,30)[/INLINECODE] I works on Windows OS, Linux may behave differently. | |
Re: You have really butchered the original example code! I would suggest to reload the original code and it will work fine! | |
Re: Here is way to do it: [php]def check_pin(pin): """check if pin number pin is between 1000 and 9000""" if 1000 <= pin <= 9000: return True return False pin = int(raw_input("Enter pin number (between 1000 and 9000): ")) print check_pin(pin) [/php] | |
![]() | Re: [QUOTE=Ancient Dragon;315223]I don't know what window() does.[/QUOTE]There is Windows API function, see thread: [url]http://www.daniweb.com/code/snippet217.html[/url] ![]() |
Re: [QUOTE=Ancient Dragon;315137]I don't know about phthon but I know that can be done in C or C++ using sockets. Computers attached to a LAN (Local Area Network) do not require internet service provider but others do.[/QUOTE]Here is your answer! Use C++! You may want to repost your request in the … | |
Re: [QUOTE=vegaseat;311399] Looks like someone at the office has been messing with the code field again, sorry! Copy and pasting code is a mess now!!!!!!!!!!![/QUOTE]Gee, vegaseat you are old and blind. This is supposed to be improvement. See the little line 'Toggle Plain Text' just below the code, click on it, … | |
Re: Right now the main thing wrong are all the missing indentation that Python uses to block code. It would be nice to know what 'wordlist.txt' looks like. | |
Re: I think you can replace javascript with python code, but your webserver has to be python enabled. | |
Re: Just in case others may wonder, you put the event loop mainloop() in the wrong place: [code]from Tkinter import * class Main: def __init__(self, master): self.master = master self.master.title('Role Playing Form V1.0') self.master.geometry('300x250+350+450') #self.master.mainloop() #!!!!!!!!!! self.cmdCreate = Button(self.master, text='Create Character', command=self.create) self.cmdCreate.grid(row=0) def create(self): pass root = Tk() main=Main(root) # … | |
Re: Is this part of your doctorial theses in computer science? | |
Decided to start my own thread rather than hijack thread "Sorting" I followed ghostdog74 advice and used module re to extract numeric strings: [php]import re data_raw = """[20] [ 35+ ] age = 40 (84) 100kg $245 """ # use regex module re to extract numeric string data_list = re.findall(r"\d+",data_raw) … | |
Re: I looked at Ene's wxPython remake of vegaseat's fancy Tkinter GUI "Hello World!" code, and used the Boa Constructor IDE to do this. It took only a few minutes to create this wxPython code, since Boa has a drag/drop frame builder and writes most of the code: [code=python]# fancy "Hello … | |
Re: Thanks this info ghostdog! You must be one great regex expert! re.findall(r"(\d+)",data_raw) works great on raw_data, but when I changed 40 to 40.5 it gave me [..., '40', '5', ...] Looks like '\d+ only works on integers. Do you have any suggestions for floats? Maybe I should start new thread? … | |
Re: Any hints on how you solved it? | |
Re: This looks more like something your internet provider is doing to keep cost down! | |
![]() | Re: [QUOTE=woooee;302803]This will print your PYTHONPATH. If the path you want is not listed, and it shouldn't be because your program isn't found, then you have to use sys.path.append to add it.[code] import sys path_list= sys.path for eachPath in path_list : print eachPath[/code][/QUOTE] PYTHONPATH is only used by Python internally to … ![]() |
Re: Not too long ago I wrote Python program to check the onset and degree of color blindness. Actually posted the beginnings of it as snippet here: [url]http://www.daniweb.com/code/snippet457.html[/url] If you are interested in things medical, you can check out BioPython at: [url]http://biopython.org/wiki/Main_Page[/url] | |
Re: Pack it into a function then you can use it again and again: [php]def get_integer(): '''loops until integer value is entered, then returns it''' while True: try: num = int(raw_input("Enter integer number: ")) return num except ValueError: print "Please, enter integer number!" # get integer value from the user val … | |
Re: This puts little more light on it: [code]def fib(n): print "Computing fib:", n if 0 < n < 3: value = 1 print "1Returning value: ", value elif n == 0: value = 0 print "2Returning value: ", value else: value = fib(n-1)+fib(n-2) print "3Returning value: ", value return value … | |
Re: I think wxPython demos were written by my C++ professor or his father. He always uses the C++ trick of putting in obscure header files, to make student's life harder! I have simplified some code that works without those extra imports at: [url]http://www.daniweb.com/code/snippet615.html[/url] | |
Re: [QUOTE=sharky_machine;283870]Lists are mutable, Dictionaries are not.[/QUOTE]That is not true! Dictionaries are mutable! However, you cannot use mutable objects like lists and yes dictionaries for the key. Dictionary values can be most anything. Study some more and experiment with this interesting container. If you get stuck, ask more questions! | |
Re: You might have to destroy the dialog after it has been used: [code] ### uncomment the following 2 lines of code and ### the popup menu will not appear on fc5 if dlg.ShowModal() == wx.ID_OK: # do something thisresult = "a file was selected" dlg.Destroy() ### ###################### [/code] | |
Re: I think it depends on the version of Windows XP. I can repeat vegaseat's observation on my folks old desktop computer, but import uses the updated pyc file right away on a friend's brandnew laptop with the latest version of Windows XP. Does anyone now how to display the version … | |
Re: Rather than putting your selected line into Label, put it into Entry. Now you can edit it. Bind the Entry to double mouse click to load it back into Listbox at the index sel[0] you have. | |
Re: My advice, use the little utility at: [url]http://www.daniweb.com/code/snippet499.html[/url] Since this is GUI program you need to change 'console' to 'window' and give your filename .pyw extension. | |
Re: Accidental endless loops are the once you have to watch out for. The 'while loop' is more prone to this either through faulty escape logic or accidental use of the control variable: [php]# accidental endless loop # this is okay in Python for k in range(10): k = 2 print … | |
Re: For German characters I have found it simpler to replace them with acceptable equivalents. Here is an example: [code]# -*- coding: iso-8859-15 -*- str1 = 'Activest-Aktien-Großbritannien' print str1 # test str1 = str1.replace('ß', 'ss') print str1 # test str2 = 'Überländliche Fracht' print str2 str2 = str2.replace('Ü', 'Ue') str2 = … | |
Re: Here are simple programs. The console version: [code=python]# console sales tax program while True: price = float(raw_input("Enter purchase price: ")) # prevent division by zero error if price != 0: break else: print "price can not be zero!" tax = float(raw_input("Enter sales tax paid: ")) percent = 100 * tax … | |
![]() | Re: For your information, a few nice folks are working on a 'Python Tkinter GUI Builder' (ptkgb), that allows you to drag and drop Tkinter widgets on one form similar to the Delphi RAD or MS Visual stuff. Take a look at: [url]http://sourceforge.net/projects/ptkgb/[/url] |
Re: The easiest way would be to use: [code]import os os.system("echo $BASH_VERSION") [/code] | |
![]() | Re: Expanding on mawe's formula builder, this is my contribution to the equation solver: [code=python]# evaluate equation like 3x^2+2(3x-2) = 0 import re # look for digit before alpha and '(' pattern = re.compile("(\d)([A-Za-z(])") formula_raw = "3x^2+2(3x-2)" # insert '*' between digit and alpha or '(' formula = re.sub(pattern, r"\1*\2", formula_raw) … ![]() |
Re: Is this the same as thread [url]http://www.daniweb.com/techtalkforums/thread60334.html[/url] ??? | |
Re: MSVCR71.dll is the Microsoft runtime C++ library. I don't think Py2Exe is going to mess with that! You can distribute that file, but you cannot change it or get the wrath of big MS! Jython compiles Python source code down to Java bytecodes which can run directly on a JVM. … | |
Re: Nice wxPython code! MSVCP71.dll is the Microsoft C++ runtime library used by wxPython. You should install it in C:\WINDOWS\system32\. That should take care of your problems. I noticed you are using Python25, make sure that wxPython and Py2Exe are also for that version of Python. | |
Re: Sorry, I don't use Tkinter much, mostly wxPython. It looks to me that in (3) you are overwriting whatever has been in self.level_string with "Level: ". | |
Re: Seems that Linux folks use GTK and pygtk for GUI work. It looks like a good GUI, but I use the Windows OS and the whole installation process of GTK/pygtk and all the additional required things is very cumbersome. I personally like wxPython a lot. Why did you choose to … | |
Re: I am studying C++ right now in school (not my choice), and being used to Python the endless type declarations, memory allocations, and pointer this, and pointer that, to achieve very simple stuff, is cumbersome at best. Function arguments are handled with such elegance in Python! | |
Re: Rightclick the IDLE icon and check Properties. You may notice that it still wants to run under Python23. Create a shortcut of Idle.pyw in the Python25/Lib/idellib/ directory and drag it onto your display panel. Use this new icon to run IDLE. |
The End.