4,305 Posted Topics
Re: Thanks for letting us know. | |
Re: You have to apply the scrollbar to a particular widget, for example ... ''' ttk_Scrollbar101.py explore the ttk scrollbar widget ''' try: # Python27 import Tkinter as tk import ttk except ImportError: # Python3 import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() scrollbar = ttk.Scrollbar(root) scrollbar.pack(side='right', fill='y') … | |
Re: About 1 billion Valentine’s Day cards are exchanged each year. This makes it the second largest seasonal card sending time of the year | |
Re: Bright colors, water balloons, lavish gujiyas and melodious songs are the ingredients of perfect Holi. Wish you a very happy and wonderful Holi too. On an unrelated side: I wonder if daylight-savings-time is really saving anything. | |
Re: Your for loop should look like this ... #declares an empty array (list) called rainfall to #which you can append values with the append method rainfall = [] #for loop to loop from 0 to 11 #remember the 1st element of an array is at subscript 0 for index in … | |
Re: A dictionary in this case would be a list of special names you expect to find. Simply create a text file with each name on its own line that you can read into Python code and form a list or a set (removes any duplicates). You could assume that each … | |
Re: Here is an example ... # use a Tkinter label as a panel/frame with a background image # (note that Tkinter reads only GIF and PGM/PPM images) # put a button on the background image try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk … | |
Re: I have used module prettytable in the past this way ... ''' prettytable102.py explore module prettytable get prettytable-0.7.2.zip from https://pypi.python.org/pypi/PrettyTable extract the zip file and copy prettytable.py to /Lib/side-packages ''' from prettytable import PrettyTable mylist = [['a', 'b', 'c'], ['a', 'b', 'c'], ['a', 'bbbbbbbbbbbbbbbbbbb', 'c'], ['k', 'k', 'l'], ['a', 'b', … | |
Re: Another example ... http://rowinggolfer.blogspot.com/2010/05/qtreeview-and-qabractitemmodel-example.html | |
Re: A simplified version could be ... ''' text_analyze101.py a simple way to analyze text ''' text = '''\ A dad is on his way home a bit late from the office when he realizes that it's his daughter's birthday and he has not bought her a gift. So he stops … | |
Re: Make your life easier by creating a list of (average, name) tuples. That list can be sorted as is. Something like this (stick with the default dictionary as you did before) ... import collections as co # assume this is a string read from a file # showing name:score data … | |
Re: This might be a less complicated approach ... import collections as co # assume this is a string read from a file # showing name:score data on each line data_str = '''\ Charlotte:7 Charlotte:4 Charlotte:3 Chelsea:2 Chelsea:9 Chelsea:5 Jeff:1 Jeff:10''' # convert to a name:score_list default-dictionary ddict = co.defaultdict(list) for … | |
Re: An example ... # assume you have this url ... url = "https://www.python.org/downloads/release/python-343/" # the base (scheme + netloc) would be ... base = "https://www.python.org/" # the path would be ... path = "downloads/release/python-343/" # however you want to select one of these paths ... path_list = ["community/", "doc/", "community/jobs/"] … | |
Well I done it! Got bored after the holidays and bought a Raspberry Pi credit card sized computer ($35), the least expensive LED TV and a Logitech wireless Keyboard/Mouse combo. The way I ordered the kit it cost almost twice as much, but it came with a good 2.5A powersupply, … | |
One way to find the shortest distance between a series of surface (x, y) points is to let Python module itertools find the non-repeating combinations of point pairs. Now you can apply the Pythagoras' theorem to find all the distances and the minimum distance. | |
Re: Great resource ... https://www.daniweb.com/software-development/c/threads/50370/starting-c-#post234971 | |
Re: Module json is built in, but module rpg_data is custome made. | |
Re: You could also take a look at Scrapy: http://scrapy.org/ and https://pypi.python.org/pypi/Scrapy | |
Re: This might help ... http://pymotw.com/2/urllib/ | |
Re: days may not be a string do a test print with `print(type(days))` | |
Re: megaflo found an error on line 63 I took the time to correct it thanks megaflo | |
Re: You could do this ... def say(msg, optional=""): print(msg) if optional: print(optional) say('hi', 'option') ''' hi option ''' print('-'*12) say('not') ''' not ''' But this is far simpler ... def say(*args): for arg in args: print(arg) say('hi', 'option') ''' hi option ''' print('-'*12) say('not') ''' not ''' | |
Re: Here is one example that might help ... """ tk_treeview101.py see also ... http://stackoverflow.com/questions/16746387/tkinter-treeview-widget """ import os try: # Python2 import Tkinter as tk import ttk except ImportError: # Python3 import tkinter as tk import tkinter.ttk as ttk class DirectoryBrowser(tk.Frame): def __init__(self, master, path): self.path = os.path.abspath(path) self.entries = {"": … | |
Re: Error messages are poor with .kv files. One reason I don't like them. Check your log file. | |
Re: `self.top_right = ScrolledText(self, text=self.text, width=50, height=15)` the instance you get refers to the Frame object and that does not have a 'text' argument. The line `Frame.__init__(self, parent)` in class ScrolledText makes that the instance self You can test it with `print(self.top_right.config()['class'])` | |
Re: This might give you a hint ... ''' tk_label_lift_lower.py hide and show labels sharing the same grid position with lift and lower ''' try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def show2(): label1.lower() label2.lift() def show1(): label2.lower() label1.lift() root = tk.Tk() button1 … | |
Re: You can only edit within one hour after posting. Try this ... import datetime as dt now = dt.datetime.today() year = now.year # Persian new year march 21 at 2:15:11 pnewy = dt.datetime(year, 3, 21, 2, 15, 11) differ = pnewy - now print("There are {} seconds till Persian New … | |
A simple code example on how to play wave sound files with the Python module PyGame. | |
Here we use the eval() function as the backbone of a simple calculator. One table is used for the display. A second table holds the buttons for the keypad. The whole thing forms an attractive looking calculator. To test it, simply paste the code into an editor like notepad and … ![]() | |
| |
Re: Something like this ... mylist = [2,4,4] number = int("".join(str(n) for n in mylist)) print(number, type(number)) | |
A simple way to find out a Python module's location on your drive. | |
Re: The Python manual at https://www.python.org/doc/ contains a tutorial you may play with. Use the IDLE IDE that comes with your Python installation and start typing the code and try it out. Python makes it easy to experiment. John Guttag's video lectures are excellent but a little heavy on Computer Science … | |
Re: Not sure why you want to do this, but one way is to build a ringbuffer ... import collections def ringbuffer_append(item, dq=collections.deque(maxlen=3)): ''' mimics a ringbuffer of length 3 you can change maxlen to your needs ''' dq.append(item) return list(dq) # testing mylist = ringbuffer_append('red') print(mylist) mylist = ringbuffer_append('green') print(mylist) … | |
Re: numbers should be part of the instance, bad to use a global | |
Re: mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2] print(mylist) # replace mylist with an empty list mylist = [] print(mylist) # --> [] mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2] # delete part of a list, keep the first … | |
Re: The correct answer is from [url]http://www.daniweb.com/techtalkforums/thread20774.html[/url] [code] # raw_input() reads every input as a string # then it's up to you to process the string str1 = raw_input("Enter anything:") print "raw_input =", str1 # input() actually uses raw_input() and then tries to # convert the input data to a number … | |
Re: One good tool to see what is going on in strange code is to put in temporary test print() | |
Re: Ruby skills are not much in demand. My prediction is that Java demand will slowly fizzle and will be replaced by a combination of Python and C++. Python for the speed of development, and C++ for the speed of code and its large libraries. Python and C++ work very well … | |
![]() | Re: Java is very well entrenched in the CS teaching apparatus. It will take a while for this to modernize. ![]() |
Re: My horror would be to end up with a dull and boring job/career. | |
Re: I think it's called an OptionMenu ... ''' tk_OptionMenu1.py using Tkinter's Optionmenu() as a combobox allows one item to be selected use a button to show selection ''' try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def ok(): sf = "value is %s" … | |
Re: You need to double click on the code field which will highlight the code. Now you can copy and paste it to an IDE editor. The code works. Initially you may want to tell the user to click add. Once you have more than 2 balls collision response will be … | |
Re: Read the comments ... [code]# draw a checker board with Python module turtle import turtle as myTurtle def drawCheckerBoard(myTurtle, sideLength): myTurtle.speed('fastest') # turtle by default starts at (x=0, y=0) center of a (450x550) window # to pick another center lift the pen up then move # to the left -x … | |
Re: Also, when you see very repetitive code, then a function or a loop comes to mind. | |
![]() | Re: For small projects in Python I use Tkinter quite a bit. Generally I haven't used **tkdocs** for a reference because the information is scatterd amongst so many languages. The Python manual contains Ykinter and is easier to use. |
Re: Highlight your code and press **Code** on the bar above to preserve your indentations. |
The End.