vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This Python Tkinter GUI toolkit code draws a shape, and shows you when and where the mouse has been clicked within the shape.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Or you can draw using a GUI toolkit ...

# using the Zelle graphics module (derived from Tkinter)
# http://mcsp.wartburg.edu/zelle/python/graphics.py
# draw a stick figure

from graphics import *

def drawStickFigure():
    win = GraphWin("Stick figure")
    # head
    Circle(Point(100, 60), 20).draw(win)
    # body
    Line(Point(100, 80), Point(100, 120)).draw(win)
    # arms with options
    arms = Line(Point(60, 100), Point(140, 100))
    arms.setFill('red')
    arms.setWidth(10)
    arms.draw(win)
    # 2 legs
    Line(Point(100,120), Point(60,160)).draw(win)
    Line(Point(100,120), Point(140,160)).draw(win)

    # pause for click in window
    win.getMouse()
    win.close()


drawStickFigure()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

In a nutshell ...
A dictionary is an unordered set of key:value pairs sometimes
called associative arrays, mappings or hash tables.

Dictionaries are indexed with unique keys instead of ordinal offset values.
Numbers and strings can always be used as keys and can be mixed.
Dictionaries grow or shrink on an as-needed basis.
A dictionary is not a sequence like a list or tuple.

Here is an example ...

# dictionary keys are in hash order to allow for fast lookup

# create an empty dictionary
ger_eng_dic = {}  # or ger_eng_dic = dict()

# add/load new key:value pairs by using indexing and assignment
# here 'eins' is the key, 'one' is the key value
# the start of a german to english dictionary
ger_eng_dic['null'] = 'zero'
ger_eng_dic['eins'] = 'one'
ger_eng_dic['zwei'] = 'two'
ger_eng_dic['drei'] = 'three'
ger_eng_dic['vier'] = 'four'

# print loaded dictionary
# the dictionary key order allows for most efficient searching
print("Dictionary now contains (notice the seemingly random order of keys):")
for key, val in ger_eng_dic.items():
    print("%s: %s" % (key, ger_eng_dic[key]))

print('-'*30)  # 30 dashes

# find the value by key (does not change dictionary)
#print("The english word for drei is %" % ger_eng_dic['drei'])
# better
if 'drei' in ger_eng_dic:
    print("The english word for drei is %s" % ger_eng_dic['drei'])

'''result ...
Dictionary now contains (notice the seemingly random order of keys):
eins: one
drei: three
vier: four
null: zero
zwei: two
------------------------------
The english word for drei is three
'''
TrustyTony commented: short and crisp! +12
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Try this to avoid cyclical imports ...

#!/usr/bin/python
# save as menu.py

def menu1():
  from dictionary import dmenu1 
  print "Add into the list the result of a new participant."
  print "\ta to adds the score x for the last participant."
  print "\tb to inserts score x at position y in te list."
  print "\tz to go back at the main menu."
  m=int(input())
  return dmenu1[m]()

def menu2():
    print "smt"

def menu3():
    print "smt"
def menu4():
    print "smt"
def menu5():
    print "smt"
def menu6():
    print "smt"

def main():
  print "Enter: "
  print "\t1 to add into the list the result of a new participant."
  print "\t2 to modify the scores from the list."
  print "\t3 to write the participants whose score has different properties."
  print "\t4 to obtain different characteristics of participants."
  print "\t5 to filter scores."
  print "\t6 to undo the last operation."
  n=int(input())
  return dmain[n]()

if __name__ == '__main__':
    from dictionary import dmain

    main()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Let's say you have this program saved as test.py in folder "C:/Python27/Mytests/"

# save as test.py
for x in range(10):
    print(x)

Now you can do this in the Python shell and see the output...

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> execfile("C:/Python27/Mytests/test.py")
0
1
2
3
4
5
6
7
8
9
>>> 

In your case specify the D: drive.

syeda amna commented: Thank u. +1
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Hint ...

start = 7
# this will count r from start down to 0
for r in range(start, -1, -1):
    print(r)
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

numpy-MKL-1.6.2.win32-py3.3.exe
can be found at the Gohlke site

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I am exploring some of the PySide (PyQT public) widgets like the combo box, and how colors are applied ...

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

"wxPython" for Python3 may never appear. IMHO it is better to use PySide anyway, which is the official LGPL-licensed version of PyQT. It is available for all versions of Python.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

"I don't know the key to success, but the key to failure is trying to please everybody."
... Bill Cosby

Reverend Jim commented: One of my favourites +0
ChrisHunter commented: Very true, one of my own downfalls. +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

If you want to try Python, be aware that Python has switched versions from 2 to 3. A fair number of the old version 2 code samples will not work with version 3.

The latest version of Python is 3.3.0 and you can get it as a Windows msi (use the 32bit installer). It comes with a small and nimble GUI toolkit called tkinter (also has expansion modules ttk and tix). There is also a small IDE included (called IDLE) based on tkinter. A good way to write your programs and run them.

A good number of free third party modules for the various versions of Python are available from:
http://www.lfd.uci.edu/~gohlke/pythonlibs/

These include:
PIL (Python Image Library)
numpy (high speed number crunchers)
PySide (mucho GUI toolkit based on QT)
PyGame (game development based on SDL)
cx_Freeze (makes exe files for Windows)
mpmath (math with high precision)
...

Ask any questions at our DaniWeb Python Forum.
Start with:
http://www.daniweb.com/software-development/python/threads/20774/starting-python#post104834

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

"A fool thinks himself to be wise, but a wise man knows himself to be a fool."
... William Shakespeare

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

PySide (public license PyQT) is my preferred Python GUI toolkit. Here we explore how to test some of the widgets available and create a digital clock.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I used the above primelist code for benchmarking and got these results:

'''result (on a Toshiba Satellite P875 with an Intel Core i5 processor) ...

Python version:
 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

primelist_bw(1000000) --> 39992.52 microseconds/pass
primelist_ds(1000000) --> 37842.45 microseconds/pass
primes_numpy(1000000) --> 7044.22 microseconds/pass
------------------------------------------------------------
[999953, 999959, 999961, 999979, 999983]
[999953, 999959, 999961, 999979, 999983]
[999953, 999959, 999961, 999979, 999983]


Python version:
 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)]

primelist_bw(1000000) --> 54640.40 microseconds/pass
primelist_ds(1000000) --> 54041.90 microseconds/pass
primes_numpy(1000000) --> 8586.35 microseconds/pass
------------------------------------------------------------
[999953, 999959, 999961, 999979, 999983]
[999953, 999959, 999961, 999979, 999983]
[999953, 999959, 999961, 999979, 999983]


Python version:
 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)]

primelist_bw(1000000) --> 64008.36 microseconds/pass
primelist_ds(1000000) --> 64330.56 microseconds/pass
primes_numpy(1000000) --> 8462.06 microseconds/pass
------------------------------------------------------------
[999953, 999959, 999961, 999979, 999983]
[999953, 999959, 999961, 999979, 999983]
[999953, 999959, 999961, 999979, 999983]
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A class that creates a persistent list can be used for some interesting applications ...

'''Class__persist1.py
find all integers in a series of texts
create a persistent list of all finds
tested with Python27, Python32 and Python33
'''

import re

class Persist_list_int():
    """
    class to make a list persistent
    """
    def __init__(self):
        # this list is persistent
        self.all_items = []

    def __call__(self, text):
        """
        allows class instance to be called with argument text
        """
        # just a simple test of the persistent list
        # regex to find all integers in a given text
        items = re.findall("\d+", text)
        self.all_items.extend(items)
        return self.all_items


# create class instance
find_int = Persist_list_int()

# call instance
print(find_int('12 days and 17 hours'))   # ['12', '17']
print(find_int('about 15 minutes ago'))   # ['12', '17', '15']
print(find_int('we are leaving at 6:45')) # ['12', '17', '15', '6', '45']
print(find_int('you owe me $123.48'))     # ['12', '17', '15', '6', '45', '123', '48']
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Temperature conversion from C to F or F to C is allways popular. Here is a way to make you scratch your head ...

'''Class_Temperature2.py
a class to convert F to C or C to F

tested with python32, python33
Python27 needs class Temperature(object)
'''

class Temperature():
    """
    allows you to convert F to C or C to F
    double underline prefix makes method private to class
    """
    def __init__(self):
        self.celsius = 0.0
    def __getFahrenheit(self):
        return 32 + (1.8 * self.celsius)
    def __setFahrenheit(self, f):
        self.celsius = (f - 32) / 1.8
    # property() combines get and set methods into one call
    # celsius and fahrenheit define each other
    # only one is needed to be given
    fahrenheit = property(__getFahrenheit, __setFahrenheit)


# create the class instance
t = Temperature()

# convert Celcius to Fahrenheit
t.celsius = 0
print("%0.1f C = %0.1f F" % (t.celsius, t.fahrenheit))

# convert Fahrenheit to Celsius
t.fahrenheit = 98
print("%0.1f F = %0.1f C" % (t.fahrenheit, t.celsius))

'''result ...
0.0 C = 32.0 F
98.0 F = 36.7 C
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Take a look at this ...

def main():
    # getInputs() returns num1 an num2
    num1, num2 = getInputs()
    # calculateWork(num1, num2)
    # needs num1 and num2 arguments
    # and returns answer
    answer = calculateWork(num1, num2)
    print (answer)

def getInputs():
    num1 = int(input("Please enter your first number: "))
    num2 = int(input("Please enter your second number "))
    return num1, num2

def calculateWork(a, b):
    return a*b

main()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Are the Russians boozing so much to keep their blood from freezing?

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Looks ike you are using Python3, so '/' will be floating point division and '//' an integer division. You can always test drive it ...

Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 2/3
0.6666666666666666
>>> 2//3
0
>>> 
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Windows: Just another pane in the glass.

Actually, I like Windows7.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Bill Gates is the richest person in the USA according to the latest article in Fortune magazine. His wealth is estimated at 66 Billion Dollars.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Viruses are well supported by their authors, are frequently updated, and tend to become more sophisticated as they mature. So there! Windows is not a virus.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Don't forget that the Python 3.3 release date is September 22, 2012
Some of the modules listed at the gohlke site are for Python 3.3

I have played around with the prerelease version, there are some improvements, but also some bugs.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Check
http://www.lfd.uci.edu/~gohlke/pythonlibs/
for all sorts of science based Python modules

Gribouillis commented: nice list +13
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit ...

TrustyTony commented: Good to collect some quality ways to summarize the zillion threads here in Daniweb. These are also kinds which newbies can not claim their own ;-) +12
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Hmmmm ...

# -*- coding: latin1 -*-

# coding adds proper letters to isalpha() with Python 3.2
# but not Python 2.7

def is_alpha_space(name):
    return (any(c.isalpha() for c in name) and
            all(c.isalpha() or c == ' ' for c in name))

name = "Väinö Veijalainen"
print(is_alpha_space(name))  # True

name = "Mark Zumkoff@"
print(is_alpha_space(name))  # False

name = "    "
print(is_alpha_space(name))  # False
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Write a Python program that compares two text strings and gives a percent rating how well they match.

One hint ...

'''str_set_xor1.py
show the words that are in one text or the other
but not in both
'''

text1 = """\
Mary had a little lamb
its fleece was white as snow
and everywhere that Mary went
the lamb was sure to go"""

text2 = """\
Mary has a little lamp
his fleece as white as snow
and where ever that Mary went
the lamp is sure to go"""

# create a set of unique words for text1
set1 = set(text1.split())
# dito for text2
set2 = set(text2.split())

# create a new set with words in either
# set1 or set2 but not both (exclusive or)
set_xor = set1.symmetric_difference(set2)

# show result
print("%d words are different" % len(set_xor))
print('-'*22)
for word in set_xor:
    print(word)

'''result ...
11 words are different
----------------------
his
was
is
everywhere
its
lamb
where
had
lamp
has
ever
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Pack that into a function and add some safe-guards ...

def is_alpha_space(name):
    """
    return True if all characters in name are alpha or white space
    """
    # strip off any leading/trailing white spaces
    name = name.strip()
    if len(name) < 1:
        return False
    return not len([c for c in name if not (c.isalpha() or c.isspace())])

name = "Mark Zumkoff"
print(is_alpha_space(name))  # True

name = "Mark Zumkoff!"
print(is_alpha_space(name))  # False

name = "    "
print(is_alpha_space(name))  # False
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

In other words ...

f = open("c:/users/verzo/desktop/hello.txt")
text = f.read()
print(text)
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Two movies I saw in the theater, and thought they were worth seeing again. So I bought the DVDs:

"Crazy Stupid Love" with Steve Carell and Lulianne Moore.

"Friends With Benefits" with Mila Kunis and Justin Timberlake.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This are the 100 most popular names given to baby girls in the US from 1900 to 1910:
Mary,Helen,Margaret,Anna,Ruth
Elizabeth,Dorothy,Marie,Florence,Mildred
Alice,Ethel,Lillian,Gladys,Edna
Frances,Rose,Annie,Grace,Bertha
Emma,Bessie,Clara,Hazel,Irene
Gertrude,Louise,Catherine,Martha,Mabel
Pearl,Edith,Esther,Minnie,Myrtle
Ida,Josephine,Evelyn,Elsie,Eva
Thelma,Ruby,Agnes,Sarah,Viola
Nellie,Beatrice,Julia,Laura,Lillie
Lucille,Ella,Virginia,Mattie,Pauline
Carrie,Alma,Jessie,Mae,Lena
Willie,Katherine,Blanche,Hattie,Marion
Lucy,Stella,Mamie,Vera,Cora
Fannie,Eleanor,Bernice,Jennie,Ann
Leona,Beulah,Lula,Rosa,Ada
Ellen,Kathryn,Maggie,Doris,Dora
Betty,Marguerite,Violet,Lois,Daisy
Anne,Sadie,Susie,Nora,Georgia
Maude,Marjorie,Opal,Hilda,Velma

... and these are the names for the years 2000 to 2010:
Emily,Madison,Emma,Hannah,Abigail
Olivia,Ashley,Samantha,Alexis,Sarah
Elizabeth,Isabella,Alyssa,Grace,Lauren
Taylor,Jessica,Brianna,Kayla,Sophia
Anna,Natalie,Victoria,Chloe,Sydney
Jasmine,Hailey,Megan,Rachel,Morgan
Julia,Destiny,Ava,Jennifer,Kaitlyn
Mia,Katherine,Alexandra,Haley,Savannah
Nicole,Maria,Allison,Mackenzie,Stephanie
Brooke,Amanda,Ella,Makayla,Faith
Kaylee,Jenna,Andrea,Katelyn,Mary
Jordan,Gabrielle,Rebecca,Paige,Madeline
Kimberly,Trinity,Zoe,Michelle,Sara
Lily,Kylie,Alexa,Caroline,Vanessa
Amber,Angelina,Gabriella,Lillian,Riley
Sierra,Danielle,Leah,Jada,Autumn
Erin,Maya,Ariana,Audrey,Isabel
Sofia,Marissa,Bailey,Jacqueline,Melissa
Claire,Evelyn,Shelby,Jocelyn,Mariah
Avery,Leslie,Melanie,Arianna,Aaliyah

Write a Python program that finds any names that are still popular over a hundred year span.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This shows you how to use a helper function when sorting ...

'''sort_by_last_name1.py
sort names in format "first middle last" by the last name
'''

import pprint

def by_last_name(name):
    """
    helper function to sort by last name
    assume names are "first middle last"
    """
    return name.split()[-1]

# some sample names for testing
# format is first middle last
names = """\
Fred M. Ferkel
Carolus D. Arm
Carl S. Gustafson
Ben M. Over
Rosa X. Parker
Larry Marsh
Lola Q. Zumokar
Heinrich S. W. Buzen
"""

# convert to a list
name_list = [name for name in names.split('\n') if name]

print("names unsorted:")
pprint.pprint(name_list)

print('-'*35)

print("names sorted by last name:")
pprint.pprint(sorted(name_list, key=by_last_name))

'''result >>
names unsorted:
['Fred M. Ferkel',
 'Carolus D. Arm',
 'Carl S. Gustafson',
 'Ben M. Over',
 'Rosa X. Parker',
 'Larry Marsh',
 'Lola Q. Zumokar',
 'Heinrich S. W. Buzen']
-----------------------------------
names sorted by last name:
['Carolus D. Arm',
 'Heinrich S. W. Buzen',
 'Fred M. Ferkel',
 'Carl S. Gustafson',
 'Larry Marsh',
 'Ben M. Over',
 'Rosa X. Parker',
 'Lola Q. Zumokar']
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Write a Python program the finds the longest word in a given text string.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I am an expert of electricity. My father occupied the chair of applied electricity at the state prison.
--> W. C. Fields

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Just a few more explorations using a Python class to mimic a C Structure or Pascal Record. Loading the record from a csv type data file, displaying the data and sorting and searching the data in various ways.

Ene Uran commented: helpful +12
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Just a simple text editor using the Tkinter expansion TIX. You are encouraged to improve this program with added functions.
TIX is included with the latest Python distributions.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I am happy to report that the PyGTK option works on Windows, something that wasn't easy to install with Python on a Windows box.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The portable version of Python (versions 2.7 and 3.2 are available) can be run from your hard drive or a flash drive. In many ways this makes your live easier, since a lot of libraries are included already. Also, you can take your code to a friend on a flash drive and show it off.

However, it is for Windows machines only!

Portable Python 2.7.3.1
from:
http://www.portablepython.com/wiki/PortablePython2.7.3.1

This package contains following applications/libraries:

 PyScripter v2.5.3
 NymPy 1.6.1
 SciPy 0.10.1
 Matplotlib 1.1.0
 PyWin32 216
 Django 1.4
 PIL 1.1.7
 Py2Exe 0.6.9
 wxPython 2.9.3.1
 NetworkX 1.6
 Lxml 2.3
 PySerial 2.5
 PyODBC 3.0.2
 PyGame 1.9.1
 PyGTK 2.24.2
 PyQt 4.9.1-1 
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This shows you how to draw on the PySide/PyQT canvas and save your drawing ...

'''ps__drawcircles_save1.py
draw circles and save them as an image file
tested with pyside474 and Python27/Python32
'''

from PySide.QtCore import *
from PySide.QtGui import *

class DrawEllipse(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        # setGeometry(x_pos, y_pos, width, height)
        self.setGeometry(300, 300, 640, 480)

    def paintEvent(self, event):
        # create a blank (640x480, white background) image with 
        # a painting program like GIMP (http://www.gimp.org/)
        image = QImage('blank640x480.png')        
        paint = QPainter()
        # the paint canvas is the blank image
        # paints in memory only
        paint.begin(image)
        # optional
        paint.setRenderHint(QPainter.Antialiasing)
        # optionally make a blue drawing background
        paint.setBrush(Qt.blue)
        paint.drawRect(event.rect())
        # this will draw red outlined circles
        paint.setPen(Qt.red)

        # for a circle make the 2 radii the same
        radx = 100
        rady = 100
        # optionally fill circles yellow
        paint.setBrush(Qt.yellow)
        for n in range(125, 420, 20):
            # set center x,y coordinates
            center = QPoint(n*1.25, n-12)
            # also change the 2 radii
            radx -= 10
            rady -= 10
            paint.drawEllipse(center, radx, rady)

        paint.end()
        # now save the modified image, format needs to match blank format
        fname = "mycircles.png"
        image.save(fname)
        s = "File %s saved" % fname
        self.setWindowTitle(s)
        # load the saved image and show on the real paint canvas
        image2 = QPixmap(fname)
        paint.begin(self)
        paint.drawPixmap(0, 0, image2)
        paint.end()        


app = QApplication([])
circles = DrawEllipse()
circles.show()
app.exec_()
Ene Uran commented: clever +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You can use a Tkinter label as a frame with a background image ...

# 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

root = tk.Tk()
root.title('background image')

# pick a .gif image file you have in the working directory
# or give full path to the image file
image = tk.PhotoImage(file="roses.gif")
# get the width and height of the image
w = image.width()
h = image.height()
# position coordinates of root 'upper left corner'
x = 200
y = 50
# size the root to fit the image
root.geometry("%dx%d+%d+%d" % (w, h, x, y))

# tk.Frame has no image argument
# so use a label as a panel/frame
panel = tk.Label(root, image=image)
panel.pack(side='top', fill='both', expand='yes')

# put a button widget on the panel
button = tk.Button(panel, text='button widget')
button.pack(side='top', pady=5)

# save the panel's image from 'garbage collection'
panel.image = image

# start the event loop
root.mainloop()
Ene Uran commented: timely +12
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Using a GUI toolkit like Tkinter construct a 7 segment numeric display.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

What do you expect the results to be?

tuple_list = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
for first, second, third in tuple_list:
    print(second)
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A closer look at the Tkinter multiline Text widget ...

# explore the Tkinter multiline Text widget
# add a vertical scroll feature
# vegaseat

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

class TextScroll(object):
    def __init__(self, master):
        """creates a text display area with a vertical scrollbar"""
        scrollbar = tk.Scrollbar(root)
        # text entry field, width in chars, height in lines of text
        self.text = tk.Text(root, yscrollcommand=scrollbar.set,
            width=80, height=30)
        scrollbar.config(command=self.text.yview)
        scrollbar.pack(side='right', fill='y')
        self.text.pack(side='left', expand=0, fill='both')

    def add_text_end(self, data):
        '''
        add text to the end of present text
        you need to supply needed newline characters
        '''
        self.text.insert('insert', data)

    def add_text_at(self, data, line=1, col=0):
        '''
        adds text at specified line and column
        line starts with 1 and column with 0
        '''
        start = "%d.%d" % (line, col)
        self.text.insert(start, data)

    def get_text_at(self, line=1, col=0, size=1):
        '''
        get text at specified line, column and size of char
        line starts with 1 and column with 0
        '''
        start = "%d.%d" % (line, col)
        end_col = col + size
        end = "%d.%d" % (line, end_col)
        print(start, end)  # test
        return self.text.get(start, end)

root = tk.Tk()
root.title('scrollable text area')

ts = TextScroll(root)

str1 = """\
use 
ctrl+c to copy selected text, 
ctrl+x to cut selected text,
ctrl+v to paste, and 
ctrl+/ to select all    
"""

ts.add_text_end(str1)

# notice newline character '\n'
# also pad ahead with newlines to accommodate line 9
# a little odd but has to be done
str2 = "\nGive it a try!"
ts.add_text_end(str2)

# to add …
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

If you want to see the possible options for a Tkinter widget, for instance Text use key() ...

# Python27 (with Python3 change Tkinter to tkinter)

from Tkinter import *
import pprint

# no options given
text = Text()

# shows possible options for Text widget
pprint.pprint(text.keys())

'''output >>>
['autoseparators',
 'background',
 'bd',
 'bg',
 'blockcursor',
 'borderwidth',
 'cursor',
 'endline',
 'exportselection',
 'fg',
 'font',
 'foreground',
 'height',
 'highlightbackground',
 'highlightcolor',
 'highlightthickness',
 'inactiveselectbackground',
 'insertbackground',
 'insertborderwidth',
 'insertofftime',
 'insertontime',
 'insertwidth',
 'maxundo',
 'padx',
 'pady',
 'relief',
 'selectbackground',
 'selectborderwidth',
 'selectforeground',
 'setgrid',
 'spacing1',
 'spacing2',
 'spacing3',
 'startline',
 'state',
 'tabs',
 'tabstyle',
 'takefocus',
 'undo',
 'width',
 'wrap',
 'xscrollcommand',
 'yscrollcommand']
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

If you want help with any of the Tkinter widgets, for instance Text, do this ...

# Python27 (with Python3 change Tkinter to tkinter)

from Tkinter import *

help("Tkinter.Text")
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

People who can code in biology, medicine, government, sociology, physics, history, and mathematics are respected and can do amazing things to advance those disciplines.
--- Zed A. Shaw

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You can animate a drawn object in PyGame this way ...

'''PG_rectangle_animate1.py
exploring Python game module pygame
free from: http://www.pygame.org

draw a rectangle on a white background and animate it
by erasing and moving the object
uses pygame class Rect and its method move()
'''

import pygame as pg

# pygame uses (r, g, b) color tuples
white = (255, 255, 255)
blue = (0, 0, 255)
red = (255, 0, 0)
green = (0, 255, 0)

# create a 400 x 300 pixel display window
win = pg.display.set_mode((400, 300))
# optional title bar caption
pg.display.set_caption('Pygame Rectangle Animation')
# default background is black, so make it white
win.fill(white)


# x1 and y1 are the upper left corner coordinates
# w and h are the width and height of rect
x1 = y1 = 15
w = 30
h = 20
# set up rect via pg class Rect(left, top, width, height)
rect = pg.Rect(x1, y1, w, h)
# width of 0 (default) fills the rectangle
# otherwise it is thickness of outline
width = 0
# draw a blue rectangle ...
# draw.rect(Surface, color, rect, width)
pg.draw.rect(win, blue, rect, width)

for delta in range(0, 480):
    # initially move toward the bottom
    # when bottom of win is near
    # move rectangle to the right
    if delta > 240:
        x = delta - 240
        y = 240
    else:
        x = 0
        y = delta
    # update screen
    pg.display.flip()
    # small time delay
    milliseconds = 25
    pg.time.delay(milliseconds)
    # this …
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Now back to some PyGame exploration ...

'''PG_rectangle1.py
exploring Python game module pygame
free from: http://www.pygame.org

draw a number of rectangles on a white background
use pygame class Rect and its methods inflate() and move()
'''

import pygame as pg

# pygame uses (r, g, b) color tuples
white = (255, 255, 255)
blue = (0, 0, 255)
red = (255, 0, 0)
green = (0, 255, 0)

# create a 300 x 300 pixel display window
win = pg.display.set_mode((300, 300))
# optional title bar caption
pg.display.set_caption('Pygame Rectangle Drawings')
# default background is black, so make it white
win.fill(white)


# x1 and y1 are the upper left corner coordinates
# w and h are the width and height of rect
x1 = y1 = 50
w = h = 200
# set up rect via pg class Rect(left, top, width, height)
# to get utility method access
rect = pg.Rect(x1, y1, w, h)
print(rect, type(rect))  # test
# width of 0 (default) fills the rectangle
# otherwise it is thickness of outline
width = 2
# draw a blue rectangle ...
# draw.rect(Surface, color, rect, width)
pg.draw.rect(win, blue, rect, width)

# shrink rect and draw again
rect2 = rect.inflate(-20, -20)
pg.draw.rect(win, red, rect2, width)
print(rect2)  # test

# expand rect and draw again
rect3 = rect.inflate(20, 20)
pg.draw.rect(win, green, rect3, width)
print(rect3)  # test

# shrink rect, move it and draw again
rect4 = rect.inflate(-70, -70)
rect5 = rect4.move(60, 60)
print(rect4, rect5)  # test
pg.draw.rect(win, red, rect5, …