Ene Uran 638 Posting Virtuoso

Something like this should be faster, since it avoids the use of function calls:

text = """\
A list of Pythonyms ...

pythonanism: spending way too much time programming Python
pythoncology: the science of debugging Python programs
pythondemic: something bad that lots of Pyton programmers do
pythonerous: something hard to do in Python
pythong: a short piece of Python code that works
pythonorean: someone who knows the esoteric technical aspects of Python
pythonus: something you don't want to do in Python
pythonym: one of these words
ptyhoon: someone who is really bad at Python
sython: to use someone else's Python code
pythug: someone who uses python to crash computers
Pythingy: a function or tool that works, but that you don't understand
Pythonian: somebody that insists on using a very early version of python
PythUH? -  block of code that yields a very unexpected output
Pythealot:  a Python fanatic
"""

spaces = 0
for c in text:
    # add to the count of spaces
    if c == " ":
        spaces += 1

print( "This text has %d spaces" % spaces )
Ene Uran 638 Posting Virtuoso

Sorry, my bad, onCreateDb() is okay, didn't read it right.

Ene Uran 638 Posting Virtuoso

The way you have written it, onCreateTable() doesn't seem to return anything. Maybe you should write a simpler test program first.

Ene Uran 638 Posting Virtuoso

With all these additional 'forced users' maybe Microsoft stock will go up for a change? I am stuck with Vista at work and at home, and I hate it!

Ene Uran 638 Posting Virtuoso

There is the Pyglet multimedia module from:
http://www.pyglet.org/index.html
You can download the Windows installer:
http://pyglet.googlecode.com/files/pyglet-1.1.2.msi
and the documentation:
http://pyglet.googlecode.com/files/pyglet-1.1.2-docs.zip


AVbin is a thin wrapper around FFmpeg a collection of audio and video codecs widely used in projects such as mplayer, xine, gstreamer and VLC.
It is needed to play .ogg and .mp3 sound files download:
avbin-win32-5.zip from http://code.google.com/p/avbin/
and install avbin.dll into Windows/System32 directory

AVbin and pyglet are also available for Unix/Linux systems.

Here is a typical pyglet example:

# load and show an animated gif file using module pyglet
# download module pyglet from: http://www.pyglet.org/download.html
# pyglet is available for Windows and Unix/Linux systems
# the animated dinosaur-07.gif file is in the public domain
# download from: http://www.gifanimations.com
# notice that the event loop uses a function decorator

import pyglet

# pick an animated gif file you have in the working directory
ag_file = "dinosaur-07.gif"
animation = pyglet.resource.animation(ag_file)
sprite = pyglet.sprite.Sprite(animation)

win = pyglet.window.Window(width=sprite.width, height=sprite.height)

# set window background color = (r, g, b, alpha)
# each value goes from 0.0 to 1.0
green = (0, 1, 0, 1)
pyglet.gl.glClearColor(*green)

@win.event
def on_draw():
    win.clear()
    sprite.draw()

pyglet.app.run()
Ene Uran 638 Posting Virtuoso

You can use simple string functions:

html = """\
<html>
<head>
   <title>Ordered List Example</title>
</head>
<body bgcolor="#FFFF00" text="#FF0000">
<OL STYLE = "font-family: comic sans ms; font-size:10pt">
   <LI>Religious tolerance</LI>
   <LI>Exact estimate</LI>
   <LI>Military Intelligence</LI>
   <LI>Passive aggression</LI>
   <LI>Tight slacks</LI>
   <LI>Business ethics</LI>
   <LI>Advanced BASIC</LI>
   <LI>Extinct Life</LI>
   <LI>Pretty ugly</LI>
   <LI>Genuine imitation</LI>
</OL>
</body>
</html>
"""

# erase just "<title>" 
print(html.replace("<title>", ""))

print('-'*50)

# erase "<title>" and "</title>"
print(html.replace("<title>", "").replace("</title>", ""))
Ene Uran 638 Posting Virtuoso

Use SetBitmapSelected() only if you want the different image to show as long as the button is pressed. For what you have in mind, you may want to use SetBitmapLabel():

# playing with wxPython's
# wx.BitmapButton(parent, id, bitmap, pos, size, style)
# show a different image for selected (depressed) button
# change the button image on button click 

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        # create a BitmapButton as an input widget
        # pick a button image file you have (.bmp .jpg .gif or .png)
        image_file1 = r".\cards\Deck1.gif"
        self.image1 = wx.Bitmap(image_file1)
        image_file2 = r".\cards\DK.gif"
        self.image2 = wx.Bitmap(image_file2)
        
        self.button = wx.BitmapButton(self, wx.ID_ANY, bitmap=self.image1,
            pos=(10, 20),
            size=(self.image1.GetWidth()+15, self.image1.GetHeight()+15))
        # bind mouse click event to an action
        self.button.Bind(wx.EVT_BUTTON, self.on_click)
        # create an output widget
        self.label = wx.StaticText(self, wx.ID_ANY, "", pos=(10, 100))

    def on_click(self, event):
        """response to button press/click"""
        # changes the images on button click for 2.5 seconds
        self.button.SetBitmapLabel(self.image2)
        self.Update()
        wx.Sleep(2.5)
        self.button.SetBitmapLabel(self.image1)


app = wx.App()
# create a MyFrame instance and show the frame
MyFrame(None, 'testing the wx.BitmapButton()', (400, 300)).Show()
app.MainLoop()
Ene Uran 638 Posting Virtuoso

Do you mean something like that?

import random

def main():
    ##Open a file
    outfile = open('numbers.txt', 'w')
    for count in range(10):
        ##Get random numbers
        rebmun = random.randint(1,99)
        outfile.write(str(rebmun) + '\n')
    outfile.close()

    # read the file you just created
    text = open('numbers.txt','r').read()
    num_list = text.split()
    
    # create a dictionary with ix:val pairs
    num_dict = {}
    for ix, val in enumerate(num_list):
        # test only
        print( ix, val)
        num_dict[ix] = int(val)
        
    # test result
    print('-'*70)
    print(num_dict)

main()

"""
my output -->
(0, '98')
(1, '51')
(2, '97')
(3, '60')
(4, '29')
(5, '23')
(6, '65')
(7, '1')
(8, '56')
(9, '56')
----------------------------------------------------------------------
{0: 98, 1: 51, 2: 97, 3: 60, 4: 29, 5: 23, 6: 65, 7: 1, 8: 56, 9: 56}

"""
Ene Uran 638 Posting Virtuoso

Is there a gui library that has already been ported to python 3? I'm interested in using some of the new python 3 features in the back end for my project.

For the time being you will have to use good old Tkinter that ships with Python3.0.

Ene Uran 638 Posting Virtuoso

Vpython and wxPython each use their own event loops, so it will not be easy and very smooth.

Ene Uran 638 Posting Virtuoso

Using
class UpdateLabels(threading.Thread):
should work too.

Ene Uran 638 Posting Virtuoso

You simply append the directory to PYTHONPATH before you import your custom module:

import sys
# appends to PYTHONPATH  the location of the example codes
sys.path.append(r'C:\Python25\Examples')
Ene Uran 638 Posting Virtuoso

Avoid Python 2.6 if you can. It was supposed to help preparing folks for Python 3.0, but it is just confusing to most users. Also like scru mentioned, wxPython for Python 2.6 has some errors in it.

I finally managed to get my SciTE IDE editor set for Python30. Actually, it was relatively easy.

Ene Uran 638 Posting Virtuoso

You can do (a**2+b**2)**0.5 do get the proper result.

Ene Uran 638 Posting Virtuoso

Here is an example how to do this:

# encoding and decoding a cipher structure

def encode(text):
    text = "".join([c.upper() for c in text if c.isalpha() or c==" "]) 
    temp = ""
    for c in text:
        temp += code_dic[c]
    return temp

def decode(crypt):
    temp = ""
    # use groups of 5
    for x in range(0, len(crypt), 5):
        temp += rev_dic[crypt[x:x+5]]
    return temp    

def swap_dict(d):
    """swap dictionary key:value pairs using a generator expression"""
    return dict((v, k) for (k, v) in d.items())


code_dic = {
'A': '11111', 'B': '11110', 'C': '11101', 'D': '11100', 'E': '11011', 
'F': '11010', 'G': '11001', 'H': '11000', 'I': '10111', 'J': '10110', 
'K': '10101', 'L': '10100', 'M': '10011', 'N': '10010', 'O': '10001', 
'P': '10000', 'Q': '01111', 'R': '01110', 'S': '01101', 'T': '01100', 
'U': '01011', 'V': '01010', 'W': '01001', 'X': '01000', 'Y': '00111', 
'Z': '00110', ' ': '00000'}

rev_dic = swap_dict(code_dic)

text = "Python is great!"
crypt = encode(text)

print(crypt)

print('-'*40)

news = decode(crypt)

print(news)

Notice I added a space char to the dictionary to make the decoded text more readable. There was also a mistake at 'E'.

One word of advice, don't make your variable and function names too long (ala C#) or your code becomes rather hard to read!

Ene Uran 638 Posting Virtuoso

if testA:
actionA()
if testB:
actionB()
if textC:
actionC()
else:
actionDefault()

this will bypass all the others as if any of the test things arent right it will skip it and go to action default

This will not work for:
testA = True
testB = False
testC = False

Ene Uran 638 Posting Virtuoso

This would do the trick, but would not be very readable:

if testA:
    actionA()
    if testB:
        actionB()
        if testC:
            actionC()

if not(testA and testB and testC):
   actionDefault()
Ene Uran 638 Posting Virtuoso

If your block is only one statement, then you can do something like this:

number = 2
guess = 2

if number == guess: print("yep it's identical")
Ene Uran 638 Posting Virtuoso

Indentation was done on purpose, and is one of Python's features that makes its syntax more readable. Yes it forces the programmer to use proper indentation, something that is often not done in code written in C. I have seen 300 line C code where every line starts at column 1. Go to the C forum and see how many times people, trying to help, request indentation.

Here is an example of what C will let you get away with:

// example of badly written C code, it works!

#include <stdio.h>
#include <string.h>

int bin2dec(char *bin);

int main(){char bin[80]="";char *p;  int  dec;
while(strcmp(bin,"0")){printf("\n Enter binary number (0 only exits): ");
fgets(bin, sizeof(bin), stdin);if ((p = strchr(bin,'\n')) != NULL){
*p = '\0';}dec=bin2dec(bin);if (dec)
printf("\nDecimal = %d  Hexadecimal = 0x%04X  Octal = 0%o\n",dec,dec,dec);
}getchar();return 0;}int bin2dec(char *bin){int b, k, m, n;
int  len, sum = 0;len = strlen(bin) - 1;for(k = 0; k <= len; k++){
n = (bin[k] - '0');if ((n > 1) || (n < 0)){
puts("\n\n ERROR! BINARY has only 1 and 0!\n");return (0);}
for(b = 1, m = len; m > k; m--){b *= 2;}sum = sum + n * b;}return(sum);}
Ene Uran 638 Posting Virtuoso

I use one tab or four spaces
They give me no problem, so I guess:
1Tab = 4spaces

You may not have a problem with your tabs and your tab setting, but I have run into plenty of problems with other folks' code that have used tabs. Please avoid tabs!

Ene Uran 638 Posting Virtuoso

You could use Hide() and Show(), or, if the frames are equal in size, position them on top of each other:

# create two frames with wxFrame, only one is showing

import wx

class Frame1(wx.Frame):
    def __init__(self, parent, mytitle):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle)
        self.SetBackgroundColour("green")
        # pass frame1 to frame2 as instance self
        self.frame2 = Frame2(None, 'Frame1', self)

        # create input widgets
        self.button1 = wx.Button(self, wx.ID_ANY, label='Frame2')
        self.button2 = wx.Button(self, wx.ID_ANY, label='Button2')
        self.button3 = wx.Button(self, wx.ID_ANY, label='Button3')
        # bind mouse event to an action
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)

        # use a box sizer to lay out widgets
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        # Add(widget, proportion, flag, border)
        sizer_v.Add(self.button1, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button2, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button3, 0, flag=wx.ALL, border=10)
        self.SetSizer(sizer_v)

        # size the frame so all the widgets fit
        self.Fit()

    def button1Click(self, event):
        """button1 has been left clicked"""
        # self is instance frame1
        self.Hide()
        self.frame2.Show()


class Frame2(wx.Frame):
    def __init__(self, parent, mytitle, frame1):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle)
        self.SetBackgroundColour("brown")
        self.frame1 = frame1

        # create input widgets
        self.button1 = wx.Button(self, wx.ID_ANY, label='Frame1')
        self.button2 = wx.Button(self, wx.ID_ANY, label='Button2')
        self.button3 = wx.Button(self, wx.ID_ANY, label='Button3')
        # bind mouse event to an action
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
        # responds to exit symbol x on frame2 title bar
        self.Bind(wx.EVT_CLOSE, self.button1Click)

        # use a box sizer to lay out widgets
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        # Add(widget, proportion, flag, border)
        sizer_v.Add(self.button1, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button2, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button3, 0, flag=wx.ALL, border=10)
        self.SetSizer(sizer_v)

        # size the frame so all the widgets fit
        self.Fit()

    def button1Click(self, event):
        """button1 has been left clicked"""
        # self is instance frame2
        self.Hide() …
Ene Uran 638 Posting Virtuoso

Use wxPython's wx.lib.dialogs.ScrolledMessageDialog() if you have to bring up a message box with a large amount of information:

# for a large information/message text uase wxPython's
# wx.lib.dialogs.ScrolledMessageDialog() widget

import wx
import wx.lib.dialogs

class MyPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.SetBackgroundColour("blue")

        # create an input widget
        self.button1 = wx.Button(self, wx.ID_ANY,
            label='The Zen of Python', pos=(10, 20))
        # bind mouse event to an action
        self.button1.Bind(wx.EVT_BUTTON, self.onAction)

    def onAction(self, event):
        """ some action code"""
        # pick an informative textfile you have in the
        # working directory (or use full path)
        fin = open("ZenPy.txt", "r")
        info = fin.read()
        fin.close()

        dlg = wx.lib.dialogs.ScrolledMessageDialog(self, info,
            "The Zen of Python, by Tim Peters ...")
        dlg.SetBackgroundColour('brown')
        dlg.ShowModal()


info_text = """\
The Zen of Python, by Tim Peters ...

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one, and preferably only one obvious way to do it.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea, let's do more of them!
"""

# create …
Ene Uran 638 Posting Virtuoso

Taking a look at wxPython's w.Image() widget, and how you can and could adjust the images red, green, blue and alpha content:

# experimants with wxPython wxImage(name, type)
# adjust the alpha (transparency) of an image
"""
type:
wx.BITMAP_TYPE_BMP  Load a Windows bitmap file
wx.BITMAP_TYPE_GIF  Load a GIF bitmap file
wx.BITMAP_TYPE_JPEG  Load a JPEG bitmap file
wx.BITMAP_TYPE_PNG  Load a PNG bitmap file
wx.BITMAP_TYPE_PCX  Load a PCX bitmap file
wx.BITMAP_TYPE_PNM  Load a PNM bitmap file
wx.BITMAP_TYPE_TIF  Load a TIFF bitmap file
wx.BITMAP_TYPE_XPM  Load a XPM bitmap file
wx.BITMAP_TYPE_ICO  Load a Windows icon file (ICO)
wx.BITMAP_TYPE_CUR  Load a Windows cursor file (CUR)
wx.BITMAP_TYPE_ANI  Load a Windows animated cursor file (ANI)
wx.BITMAP_TYPE_ANY  Will try to autodetect the format
"""

import wx

class ImagePanel(wx.Panel):
    """draw lines on a panel's wx.PaintDC surface"""
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        # pick an image file you have in the working folder
        # (can be a .jpg, .png, .gif, .bmp image file)
        image_file = 'Pythonhand3.jpg'
        self.image= wx.Image(image_file, wx.BITMAP_TYPE_JPEG)
        image_width = self.image.GetWidth()
        image_height = self.image.GetHeight()
        # set frame size (also panel) to image size
        parent.SetClientSize((image_width+20, image_height+20))
        # call on_paint() to create the canvas
        wx.EVT_PAINT(self, self.on_paint)

    def on_paint(self, event):
        dc = wx.PaintDC(self)
        # reduces flicker
        #dc = wx.BufferedDC(dc)
        # set the background colour
        dc.SetBackground(wx.Brush("WHITE"))
        dc.Clear()
        # give it a pattern
        dc.SetBrush(wx.Brush("GREY", wx.CROSSDIAG_HATCH))
        windowsize= self.GetSizeTuple()
        dc.DrawRectangle(0, 0, windowsize[0], windowsize[1])

        # adjust r g b and alpha of image
        # AdjustChannels(fr, fg, fb, fa)
        # adjust the the red, green blue and alpha factors
        # from 0.0 to 2.0 to see …
Ene Uran 638 Posting Virtuoso

This is one way to create a wxPython canvas with a background pattern on it:

# the wx.PaintDC() surface is wxPython's canvas
# create a background pattern on the canvas

import wx

class ImagePanel(wx.Panel):
    """draw lines on a panel's wx.PaintDC surface"""
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)

        wx.EVT_PAINT(self, self.on_paint)

    def on_paint(self, event=None):
        dc = wx.PaintDC(event.GetEventObject())
        # set the background colour
        dc.SetBackground(wx.Brush("WHITE"))
        dc.Clear()
        # give it a pattern using a brushed full sized rectangle
        dc.SetBrush(wx.Brush("LIGHT GREY", wx.CROSSDIAG_HATCH))
        windowsize= self.GetSizeTuple()
        dc.DrawRectangle(0, 0, windowsize[0], windowsize[1])

        # draw something cute
        for x in range(10, 180, 10):
            y = x
            r = x
            dc.SetPen(wx.Pen('red', 3))
            dc.DrawCircle(x, y, r)
            dc.SetPen(wx.Pen('blue', 3))
            dc.DrawSpline(((10, 200), (x, y), (2*x, 400-y), (370, 200)))


app = wx.App()
title = "A wx drawing surface with a background"
frame = wx.Frame(None, wx.ID_ANY, title, size=(380, 400))
ImagePanel(frame)
frame.Show(True)
app.MainLoop()
Ene Uran 638 Posting Virtuoso

Amongst other things, you can assign an image to wx.Brush(). Since the image is small, you can include it in the code as a base64 encoded image string. This has been done in previous sample codes in this thread, so here is a closer look at wxPython's canvas brush:

# a closer look at wx.Brush(colour, style=wx.SOLID)
# ene
"""
brush styles:
wx.TRANSPARENT       transparent (no fill)
wx.SOLID             solid (default)
wx.BDIAGONAL_HATCH   backward diagonal hatch
wx.CROSSDIAG_HATCH   cross-diagonal hatch
wx.FDIAGONAL_HATCH   forward diagonal hatch
wx.CROSS_HATCH       cross hatch
wx.HORIZONTAL_HATCH  horizontal hatch
wx.VERTICAL_HATCH    vertical hatch
wx.STIPPLE           stippled using a bitmap
wx.STIPPLE_MASK_OPAQUE  stippled using a bitmap's mask
"""

import wx
# to handle the base64 brush image
import cStringIO
import base64


class MyFrame(wx.Frame):
    def __init__(self, parent, title, data_stream):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(370, 310))
        self.SetBackgroundColour('white')
        # convert data_stream to bitmap
        self.bmp = wx.BitmapFromImage(wx.ImageFromStream(data_stream))
        self.Bind(wx.EVT_PAINT, self.on_paint)

    def on_paint(self, event):
        # wx.PaintDC() creates a drawing canvas
        dc = wx.PaintDC(self)

        # wx.Brush(colour, style)
        dc.SetBrush(wx.Brush('red', wx.CROSS_HATCH))
        dc.DrawRectangle(10, 15, 90, 60)

        # wx.SOLID is the default style
        dc.SetBrush(wx.Brush('red', wx.SOLID))
        dc.DrawRectangle(130, 15, 90, 60)

        dc.SetBrush(wx.Brush('red', wx.BDIAGONAL_HATCH))
        dc.DrawRectangle(250, 15, 90, 60)

        dc.SetBrush(wx.Brush('red', wx.CROSSDIAG_HATCH))
        dc.DrawRectangle(10, 105, 90, 60)

        dc.SetBrush(wx.Brush('red', wx.FDIAGONAL_HATCH))
        dc.DrawRectangle(130, 105, 90, 60)

        dc.SetBrush(wx.Brush('blue', wx.HORIZONTAL_HATCH))
        dc.DrawRectangle(250, 105, 90, 60)

        dc.SetBrush(wx.Brush('blue', wx.VERTICAL_HATCH))
        dc.DrawRectangle(10, 195, 90, 60)

        dc.DrawRectangle(130, 195, 90, 60)
        dc.SetBrush(wx.Brush('yellow', wx.TRANSPARENT))
        dc.DrawRectangle(150, 205, 90, 60)

        # a way to set up a wall-papered background
        brush_bmp = wx.BrushFromBitmap(self.bmp)
        dc.SetBrush(brush_bmp)
        dc.DrawRectangle(250, 195, 90, 60)


# a base64 encoded image string
Lips_jpg_b64 = '''\
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIf
IiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7
Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCAAgADIDASIA
AhEBAxEB/8QAGwAAAQUBAQAAAAAAAAAAAAAABgADBAUHAQL/xAAvEAABBAAGAQMCBAcAAAAAAAAB
AgMEEQAFBhIhMUETIlEUYUJxkfAVIyQyUoGh/8QAGAEAAwEBAAAAAAAAAAAAAAAABAUGAwL/xAAn
EQABAwIEBQUAAAAAAAAAAAABAAIDBBEFEzFBEiFRgdEiMmFxkf/aAAwDAQACEQMRAD8AMsUWaapY
iPuQ4jLkmUkhNpSS2hRvhRHPABNAeK+ajap1KzBSrL48hTcoqAdUlJHpoNE+7wSD2Aa/OsZ29MbS
N7jh3klSlLPf75/XAk05B4WKgw7DGPbnVHIbDTv9ItXrDMg26oy4u5S1BpDTR4TsUAqyDQ3AEAiy
e6Haka1zVxCAgRoyHUinUIKyhQ4N3x2LqiQFDs9ikJv+JV6eYZdGQeSuXLQ2Oz+G918fH3+Lso+l
80zFt9zK5mUziwfciNLKlXzXgDmjV1eMRnpi52GAgWBt8eNUTRdXy47rYmttymFBe1cdshxaUi/U
omqPN9VSuttYLI0lmZHRIjuBxpwWlQ84yKY1OyOWhE9kRZC+Wj6oJBSRyCkmj+/vi40zqZOVvIZd
IRDWv+YEoKuard3fYHXdn7Y7jmc02eh6vDoJ4zJS2uNhv26rScLHELQ4hLjagtCgClSTYI+RhYOU
togXWejlSXnc0g/ULU6pIcYZHR6KwAefFiibJN4DY2SZdIoSJL/CLKlELCiLPHIrigO+cbbgXzHQ …
Ene Uran 638 Posting Virtuoso

Just some fun with colours, using wxPython's wx.PaintDC() canvas and dc.GradientFillLinear(). Can be used as a gradient background and so on:

# using dc.GradientFillLinear() on a wxPython canvas
# cosmetic but fun

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
        self.SetBackgroundColour('#FFE4C4')   # bisque
        self.Bind(wx.EVT_PAINT, self.on_paint)

    def on_paint(self, event):
        dc = wx.PaintDC(self)

        # wx.Rect(x, y, w, h)
        # basic rectangle for all rectangles
        rect = wx.Rect(0, 0, 250, 50)

        rect.SetPosition((20, 20))
        dc.GradientFillLinear(rect, 'blue', 'white', wx.NORTH)
        dc.DrawText("blue to white going north", 30, 40)
        rect.SetPosition((20, 80))
        dc.GradientFillLinear(rect, 'blue', 'white', wx.SOUTH)
        rect.SetPosition((20, 140))
        dc.GradientFillLinear(rect, 'blue', 'yellow', wx.WEST)
        dc.DrawText("blue to yellow going west", 30, 160)
        rect.SetPosition((20, 200))
        dc.GradientFillLinear(rect, 'blue', 'yellow', wx.EAST)

        # pretty much froms a horizontal line
        rect = wx.Rect(0, 0, 250, 5)
        rect.SetPosition((20, 10))
        dc.GradientFillLinear(rect, 'red', 'green', wx.WEST)
        rect.SetPosition((20, 255))
        dc.GradientFillLinear(rect, 'red', 'green', wx.EAST)


app = wx.App(0)
MyFrame(None, 'dc.GradientFillLinear()').Show()
app.MainLoop()
Ene Uran 638 Posting Virtuoso

Zoe's bar graph example made me look a little closer at wx.Pen() -->

# the wx.PaintDC surface is wxPython's drawing canvas
# a closer look at wx.Pen(colour, width=1, style=wx.SOLID)
"""
pen styles:
wx.SOLID
wx.DOT
wx.LONG_DASH
wx.SHORT_DASH
wx.DOT_DASH
wx.TRANSPARENT

SetJoin style options:
wx.JOIN_MITER  --> default
wx.JOIN_BEVEL
wx.JOIN_ROUND

SetCap style options:
wx.CAP_ROUND
wx.CAP_PROJECTING
wx.CAP_BUTT  --> default
"""

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400, 300))
        self.SetBackgroundColour('white')
        self.Bind(wx.EVT_PAINT, self.on_paint)

    def on_paint(self, event):
        "create the canvas and draw on it"
        dc = wx.PaintDC(self)

        # wx.Pen(colour, width, style)
        # wx.SOLID is actually the default
        pen = wx.Pen('blue', 10, wx.SOLID)

        pen.SetJoin(wx.JOIN_MITER)
        dc.SetPen(pen)
        dc.DrawRectangle(10, 10, 110, 70)
        dc.DrawText('JOIN_MITER', 20, 20)

        pen.SetJoin(wx.JOIN_BEVEL)
        dc.SetPen(pen)
        dc.DrawRectangle(140, 10, 110, 70)
        dc.DrawText('JOIN_BEVEL', 150, 20)

        pen.SetJoin(wx.JOIN_ROUND)
        dc.SetPen(pen)
        dc.DrawRectangle(270, 10, 110, 70)
        dc.DrawText('JOIN_ROUND', 280, 20)

        # comes in handy if you want to use thick lines
        # for instance for a bar graph
        pen.SetCap(wx.CAP_BUTT)
        dc.SetPen(pen)
        dc.DrawLine(30, 150,  150, 150)
        dc.DrawText('CAP_BUTT', 170, 140)

        pen.SetCap(wx.CAP_PROJECTING)
        dc.SetPen(pen)
        dc.DrawLine(30, 190,  150, 190)
        dc.DrawText('CAP_PROJECTING', 170, 180)

        pen.SetCap(wx.CAP_ROUND)
        dc.SetPen(pen)
        dc.DrawLine(30, 230,  150, 230)
        dc.DrawText('CAP_ROUND', 170, 220)

        # base lines
        pen2 = wx.Pen('red')
        dc.SetPen(pen2)
        dc.DrawLine(30, 130, 30, 250)
        dc.DrawLine(150, 130, 150, 250)
        dc.DrawLine(155, 130, 155, 250)


app = wx.App(0)
MyFrame(None, 'wx.Pen() options').Show()
app.MainLoop()
Ene Uran 638 Posting Virtuoso

I played around with the wx.MiniFrame() widget that brings up a simpler frame. To make it do something useful I added the LEDNumberCtrl and made it a digital clock:

# use wxPython's wx.MiniFrame(), wx.gizmos.LEDNumberCtrl() and
# wx.Timer() to create a digital LED 24 hour clock

import wx
import wx.gizmos
import time

class MyMiniFrame(wx.MiniFrame):
    def __init__(self, parent, mytitle, mysize):
        wx.MiniFrame.__init__(self, parent, wx.ID_ANY, mytitle,
            size=mysize, style=wx.DEFAULT_FRAME_STYLE)

        self.led = wx.gizmos.LEDNumberCtrl(self, wx.ID_ANY,
            style=wx.gizmos.LED_ALIGN_CENTER)  #, pos, size, style)
        # default colours are green on black
        self.led.SetBackgroundColour("blue")
        self.led.SetForegroundColour("yellow")
        # start right away
        self.onTimer(None)
        # then let the timer kick in
        self.timer = wx.Timer(self, wx.ID_ANY)
        # update clock digits every second (1000ms)
        self.timer.Start(1000)
        self.Bind(wx.EVT_TIMER, self.onTimer)

    def onTimer(self, event):
        # get current time from your computer
        current = time.localtime(time.time())
        # time string can have characters 0..9, -, period, or space
        ts = time.strftime("%H-%M-%S ", current)
        self.led.SetValue(ts)


app = wx.App(0)
# create a MyMiniFrame instance and then show the frame
mframe = MyMiniFrame(None, 'a digital led clock', (350, 100))
mframe.Show()
app.SetTopWindow(mframe)
app.MainLoop()
Ene Uran 638 Posting Virtuoso

Why do all the extra work, if Python can do it for you?

result3=[
83,97,109,117,101,108,32,83,109,105,116,104,13,10,13,10,84,
104,97,110,107,32,121,111,117,32,102,111,114,32,108,111,111,
107,105,110,103,32,116,104,101,32,111,116,104,101,114,32,119,
97,121,32,111,110,32,116,104,101,32,105,110,99,114,101,97,115,
101,100,32,108,101,118,101,108,115,32,111,102,32,116,111,120,
105,99,32,99,104,101,109,105,99,97,108,115,32,105,110,32,116,104,
101,32,114,105,118,101,114,32,114,117,110,110,105,110,103,32,97,
108,111,110,103,115,105,100,101,32,109,121,32,104,111,109,101]

# show the text hidden in the list of ascii values
print "".join([chr(x) for x in result3])

I know, I know, not as much fun as the long way!

jlm699 commented: Sexy, simple method +1
Ene Uran 638 Posting Virtuoso

You can also let Python do the jumbling of the words and create the dictionary of word:jumble pairs:

# create a dictionary of random jumbled words for a game

import random

def jumble_word(word):
    # create a list of characters of the word
    char_list = list(word)
    # shuffle sequence in place
    random.shuffle(char_list)
    # joint to form a word again
    return "".join(char_list)

# add more words to the list as needed
words = ['armada', 'bubble', 'letter', 'banana', 'radio', 'hammer',
    'spark', 'pearl', 'target', 'zappy', 'zipper', 'organist',
    'kitchen', 'ruler', 'motorist', 'polar', 'garage', 'window']

# create a list of jumbled words
jumbles = []
for word in words:
    jumbles.append(jumble_word(word))

# create a dictionary from the two list
words_dict = dict(zip(words, jumbles))

print words_dict

"""
possible output -->
{'polar': 'aropl', 'target': 'rgaett', 'ruler': 'rleur',
'garage': 'eaaggr', 'bubble': 'beblub', 'window': 'nowdiw',
'pearl': 'aprel', 'zipper': 'pperzi', 'radio': 'idoar',
'motorist': 'rtotimos', 'letter': 'rettel', 'zappy': 'pzpay',
'armada': 'ardaam', 'spark': 'akprs', 'kitchen': 'theinck',
'hammer': 'mrameh', 'banana': 'bnanaa', 'organist': 'soiatgnr'}
"""
Ene Uran 638 Posting Virtuoso

For the many of you who still want to know the solution, make variable 'a' a global:

words = ["aero", "aesthet", "andr", "arch", "arch", "ast", "baro",\
"biblio", "bio", "cardi", "chron", "cosm", "crat", "cycl", "dem", "dont",\
"dogma", "dox", "esth"]

answers = ["air", "sense", "man", "man", "chief", "ancient", "star", "weight",\
"book", "life", "heart", "time", "universe", "rule", "circle", "people",\
"tooth", "opinion", "belief", "feeling"]

a = 0

def test():
    global a
    a = a + 1
    print "What does", words[a], "mean?"
    ans = raw_input("> ")
    if ans == answers[a]:
        print "Correct!"
        test()
    else:
        print "That is incorrect. Try again."
        a = a - 1
        test()

test()
Ene Uran 638 Posting Virtuoso

Nice game!
Just a few cosmetic things, there is a lot of empty space, so I would set the height of the frame to 180, and also use a little color with:
bkg.SetBackgroundColour('yellow')

Ene Uran 638 Posting Virtuoso

A splash screen comes up in the beginning of a program for a short time, usually showing some attractive graphics image with the programs name and author on it. Here is an example:

# a wxPython splash screen example using
# wx.SplashScreen(bitmap, splashStyle, milliseconds, parent,
#    id, pos=wx.DefaultPosition, size=wx.DefaultSize,
#    style=wxSIMPLE_BORDER|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP)
# splashStyle:
#    wx.SPLASH_CENTRE_ON_PARENT
#    wx.SPLASH_CENTRE_ON_SCREEN
#    wx.SPLASH_NO_CENTRE
#    wx.SPLASH_TIMEOUT
#    wx.SPLASH_NO_TIMEOUT
# ene

import wx

class MySplash(wx.SplashScreen):
    def __init__(self, parent, duration=2000):
        # pick a splash image file you have in the working folder
        image_file = 'CloudSplash.jpg'
        bmp = wx.Bitmap(image_file)
        # covers the parent frame
        wx.SplashScreen(bmp, wx.SPLASH_CENTRE_ON_PARENT|wx.SPLASH_TIMEOUT,
            duration, parent, wx.ID_ANY)


class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
        self.panel = wx.Panel(self, wx.ID_ANY, style=wx.SUNKEN_BORDER)

        # now make up your regular GUI stuff
        self.panel.SetBackgroundColour('yellow')
        s = "How did you like the 5 second splash screen?"
        self.label = wx.StaticText(self.panel, wx.ID_ANY, s, pos=(130, 100))


app = wx.App(0)
# create a MyFrame instance and show the frame
frame = MyFrame(None, 'wx.SplashScreen() test', (640, 480))
frame.Show()
# bring up a temporary splash screen lasting 5000 milliseconds
MySplash(frame, duration=5000)
app.MainLoop()
Ene Uran 638 Posting Virtuoso

You didn't size TextPanel.

Ene Uran 638 Posting Virtuoso

Just to add on that, I want to put my icons in a folder named icons in the same folder as my script. How do I reference them in code without error "File so and so.png does not exist"

Thanks again

On Windows you do a "./icons/myicon.ico" for example.

Ene Uran 638 Posting Virtuoso

I ran your code and it took over my computer. It took me forever to get it back to normal again. There is something wrong with your application of sendkeys or pyhook!

To tell you the truth, I won't even try to figure it out.

Ene Uran 638 Posting Virtuoso

I am a drinker and have spilled drinks on others. Will I be punished?

Ezzaral commented: heh! +11
Ene Uran 638 Posting Virtuoso

To create a window or frame with wxPython you use wx.Frame. There are some basic things you can do with a frame and I tried to put them in one spot:

# a few things you can do with wxPython's wx.Frame
# wx.Frame(parent, id, title, pos, size, style, name)
# set/change colour, cursor, position, size, title, tooltip
# blow the frame to full size and return to normal  

import wx

class MyFrame(wx.Frame):
    """inherits wx.Frame, self is the instance of the frame"""
    def __init__(self):
        # create a frame/window, no parent, default to id=wxID_ANY
        # note that id=wxID_ANY is the same as id=-1 
        # position is overwritten by Center()
        wx.Frame.__init__(self, None, wx.ID_ANY, 'original title', 
            pos=(100, 150), size=(400, 350))
        # show the frame during the creation of the instance
        # default is True, False would hide the frame
        self.Show(True)
        
        # wait just a moment, 4.5 seconds to be exact
        wx.Sleep(4.5)
        
        # this allows you to change the frame title
        self.SetTitle('changed title, colour, and cursor')
        # optionally change the cursor
        self.SetCursor(wx.StockCursor(wx.CURSOR_MAGNIFIER))
        # change the frame's colour 
        # notice British spelling of Colour
        self.SetBackgroundColour('green')
        # now clear old color, set to new color
        self.ClearBackground()
        self.Show()
        
        wx.Sleep(4.5)
        self.SetTitle('center wx.Frame horizontal')
        # optionally center the frame on the display screen
        # notice British spelling of Centre
        # wx.HORIZONTAL, wx.VERTICAL or wx.BOTH (default)
        self.Centre(wx.HORIZONTAL)
        self.Show()
        
        wx.Sleep(4.5)
        cap = 'now center wx.Frame vertical too and change size'
        self.SetTitle(cap)
        #self.Update()
        # change the size of the frame
        width, height = self.GetSize()
        # needs tuple
        self.SetSize((width+200, height-100))
        # in this …
sneekula commented: very nice basics +4
Ene Uran 638 Posting Virtuoso

The wx.SplitterWindow() could have some interesting applications:

# testing wxPython's interesting
# wx.SplitterWindow(parent, id, pos, size, style)
# the size can be changed by dragging the interior borders
#
# style =
# wx.SP_3D  draws a 3D effect border and sash (default)
# wx.SP_BORDER   draws a standard border
# wx.SP_LIVE_UPDATE  resize the child windows immediately

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        self.splitter1 = wx.SplitterWindow(self, wx.ID_ANY,
            style=wx.CLIP_CHILDREN|wx.SP_LIVE_UPDATE|wx.SP_3D)
        self.splitter2 = wx.SplitterWindow(self.splitter1, wx.ID_ANY,
            style=wx.CLIP_CHILDREN|wx.SP_LIVE_UPDATE|wx.SP_3D)

        self.panel1 = wx.Panel (self.splitter1, wx.ID_ANY)
        self.panel1.SetBackgroundColour ("red")
        self.panel2 = wx.Panel (self.splitter2, wx.ID_ANY)
        self.panel2.SetBackgroundColour ("white")
        self.panel3 = wx.Panel (self.splitter2, wx.ID_ANY)
        self.panel3.SetBackgroundColour ("blue")

        # set splitters direction and content (top or left first)
        # and sash position
        self.splitter1.SplitVertically(self.panel1, self.splitter2, 200)
        self.splitter2.SplitHorizontally(self.panel2, self.panel3, 140)


app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame(None, 'test the wx.SplitterWindow()', (400, 300)).Show()
app.MainLoop()
Ene Uran 638 Posting Virtuoso

Just some wxPython code to show you how to draw a bar chart:

# using wxPython's
# wx.lib.plot.PlotCanvas() to show a colourful bar chart

import wx
import wx.lib.plot

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        # data values indicate upper value of each bar
        # bars are drawn as thick vertical lines
        # data set one
        data1 = [5, 8, 12, 9.5, 7, 5.5, 4.5, 3]
        # data set two
        data2 = [3, 7, 13.5, 9, 6, 3.5, 2, 1]

        plot_canvas = wx.lib.plot.PlotCanvas(self)

        # create list of bars for data1
        bar_colour = 'red'
        bars1 = []
        for x in range(len(data1)):
            x1 = 2*x
            y1 = data1[x]
            bars1.append(wx.lib.plot.PolyLine([(x1, 0), (x1, y1)],
                legend='1', colour=bar_colour, width=20))

        # create list of bars for data2
        bar_colour = 'blue'
        bars2 = []
        for x in range(len(data2)):
            x1 = 2*x+1
            y1 = data2[x]
            bars2.append(wx.lib.plot.PolyLine([(x1, 0), (x1, y1)],
                legend='', colour=bar_colour, width=20))

        # set up the graphics
        gc = wx.lib.plot.PlotGraphics(bars1 + bars2,
            '2007 Sales  Vista (red)  Linux (blue)',
            'X Axis (Sales Period)',
            'Y Axis (1000 Euro)')
        # then plot it
        plot_canvas.Draw(gc, xAxis=(-0.5, 15), yAxis=(0, 15))


app = wx.App(True)
# create the MyFrame instance and then show the frame
caption = "wx.lib.plot.PlotCanvas() Bar Chart"
MyFrame(None, caption, (500, 400)).Show(True)
app.MainLoop()
Ene Uran 638 Posting Virtuoso

If you like to draw things, here is an example how to draw some basic shapes on wxPython's canvas:

# draw a few well known shapes on a wx.PaintDC() canvas

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent=None, title=None):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title)
        self.panel = wx.Panel(self, size=(350, 450))
        # this sets up the painting canvas
        self.panel.Bind(wx.EVT_PAINT, self.on_paint)
        # set frame size to fit panel
        self.Fit()

    def on_paint(self, event):
        # establish the painting canvas
        dc = wx.PaintDC(self.panel)

        # draw some lines using the given pen specs
        # from points (x1, y1) to (x2, y2)
        x1 = 50
        y1 = 20
        x2 = 300
        y2 = 20
        # first pen colour is red (thickness = 5)
        dc.SetPen(wx.Pen('red', 5))
        dc.DrawLine(x1, y1, x2, y2)
        # second pen colour is white
        dc.SetPen(wx.Pen('white', 5))
        dc.DrawLine(x1, y1+5, x2, y2+5)
        # third pen colour is blue
        dc.SetPen(wx.Pen('blue', 5))
        dc.DrawLine(x1, y1+10, x2, y2+10)

        # draw a red rounded-rectangle
        # upper left corner coordinates x, y and width, height
        # make the pen colour red (thickness = 1)
        # default brush (fill) is white
        dc.SetPen(wx.Pen('red', 1))
        x = 50
        y = 50
        w = 100
        h = 100
        rect = wx.Rect(x, y, w, h)
        # corners are quarter-circles using a radius of 8
        dc.DrawRoundedRectangleRect(rect, 8)

        # draw a red circle with yellow fill
        # center coordinates x, y and radius r
        dc.SetBrush(wx.Brush('yellow'))
        x = 250
        y = 100
        r = 50
        dc.DrawCircle(x, y, r)

        # draw an arc from point x1, y1 to point x2, y2 counter
        # clockwise along …
Ene Uran 638 Posting Virtuoso

You can use several classes in your wxPython program. This example shows you how to cross reference a widget (or variable) from one class to another:

# experiments with wxPython, reference across class instances
# from one panel class to another panel class

import wx
import time

class MakePanel1(wx.Panel):
    def __init__(self, Parent, *args, **kwargs):
        wx.Panel.__init__(self, Parent, *args, **kwargs)
        self.SetBackgroundColour('yellow')

        self.label = wx.StaticText(self, -1, " panel1 label ")

        self.hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.hbox.Add(self.label, 0, wx.ALL, 20)
        self.SetSizer(self.hbox)


class MakePanel2(wx.Panel):
    def __init__(self, Parent, *args, **kwargs):
        wx.Panel.__init__(self, Parent, *args, **kwargs)
        self.SetBackgroundColour('green')

        self.button = wx.Button(self, label=" panel2 button ")
        self.button.Bind(wx.EVT_BUTTON, self.buttonClick )

        self.hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.hbox.Add(self.button, 0, wx.ALL, 20)
        self.SetSizer(self.hbox)

    def buttonClick(self, event=None):
        # reference panel1's label via frame.panel1
        s1 = "panel1 label ..... \n"
        s2 = "the time is " + time.strftime("%H:%M:%S", time.localtime())
        frame.panel1.label.SetLabel(s1 + s2)


class MakeFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.panel1 = MakePanel1(self)
        self.panel2 = MakePanel2(self)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.panel1,1,wx.EXPAND);
        vbox.Add(self.panel2,1,wx.EXPAND);
        self.SetSizer(vbox)
        # select a frame size so everything fits
        self.Fit()


app = wx.App(0)
# instance frame is needed for later reference
frame = MakeFrame(None)
frame.Show(True)
app.MainLoop()
Ene Uran 638 Posting Virtuoso

Main purpose is to learn how to better tailor targeted ads to you and yours. Now the possibilities for other uses are limitless, or I should say; limited only by their imagination. I leave to you to speculate who "they" are.

Could be George Bush's "National Spy Agency" run by the friendly folks at Blackwater USA?

Ene Uran 638 Posting Virtuoso

Here is a way to fill your full display screen with a wx.Frame() widget, that does not show a border nor a title bar. You have to give it an exit button of your own. To be mildly playful, lets cycle through the wxPython colour data base at random:

# a full screen-display wx.Frame without border and title bar
# wxPython's wx.lib.colourdb contains about 630 different
# colour names to cycle through at random

import wx
import random
import wx.lib.colourdb as cdb

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.ID_ANY)
        # create a full screen display frame, no title bar
        self.ShowFullScreen(True, style=wx.FULLSCREEN_ALL)

        w, h = wx.DisplaySize()
        # create a panel to easily refresh colours
        self.panel = wx.Panel(self, wx.ID_ANY, size=(w, h))
        # supply an exit button in the upper right corner
        self.exitbutton = wx.Button(self.panel, wx.ID_ANY, label='X',
            pos=(w - 25, 5), size=(20, 15))
        self.exitbutton.Bind(wx.EVT_BUTTON, self.exitbuttonClick)

        cdb.updateColourDB()
        # create a list of all the colours in the colour data base
        self.colours = cdb.getColourList()

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
        # change colour every second (1000ms)
        self.timer.Start(1000)

    def onTimer(self, event):
        bg = random.choice(self.colours)
        #print bg  # test
        self.panel.SetBackgroundColour(bg)
        self.panel.Refresh()

    def exitbuttonClick(self, event):
        self.Close(True)


app = wx.App(0)
MyFrame(None).Show(True)
app.MainLoop()
Ene Uran 638 Posting Virtuoso

This is an example how to create a wx.Frame() that fills the entire display screen:

# wx.DisplaySize() gives (width, height) tuple of your display screen

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, pos=(0, 0),
            size=wx.DisplaySize())
        self.SetBackgroundColour('blue')
        s = "Frame has full display size of %d x %d" % wx.DisplaySize()
        self.SetTitle(s)


app = wx.App(0)
# instantiate class MyFrame and show
MyFrame().Show(True)
app.MainLoop()
Ene Uran 638 Posting Virtuoso

In Spain the working people are obligated by the state to contributed to the Roman Catholic Church whether they want or not. This is accomplished via income tax, but is not deductible. In fact, many even don't know that some of their money goes to the archives of the Catholic Church.

That cuts out all the cheating!

Ene Uran 638 Posting Virtuoso

I think the new Pope is quite hip! Let's support the poor fellow with your tax deductible donation!

Ene Uran 638 Posting Virtuoso

The information a statusbar can display can come handy:

# set up a customized statusbar with three display fields
# a statusbar is typically an information line at the bottom of a window

import wx
import time

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
        # fill the top part with a panel
        panel = wx.Panel(self, wx.ID_ANY, style=wx.SUNKEN_BORDER)
        panel.SetBackgroundColour("blue")

        self.sb = wx.StatusBar(self, wx.ID_ANY)
        # set the status bar with three fields
        self.sb.SetFieldsCount(3)
        # set an absolute status field width in pixels
        # (negative indicates a variable width field)
        self.sb.SetStatusWidths([-1, -1, -1])
        self.SetStatusBar(self.sb)
        # put some text into field 0 (most left field)
        self.sb.SetStatusText("some text in field 0", 0)
        self.sb.SetStatusText("some text in field 1", 1)

        # use a timer to drive a date/time string in field 3
        # here the most right field of the statusbar
        self.timer = wx.PyTimer(self.onUpdate)
        # update every 1000 milliseconds
        self.timer.Start(1000)
        self.onUpdate()

    def onUpdate(self):
        t = time.localtime(time.time())
        st = time.strftime("%d-%b-%Y   %I:%M:%S", t)
        # put date/time display string into field 2
        self.sb.SetStatusText(st, 2)


app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame(None, 'test the wx.StatusBar', (460, 300)).Show()
app.MainLoop()
Ene Uran 638 Posting Virtuoso

actually i ve pasted the exact copy of d statement from the IDLE shell.. so i don think these 2 syntax errors do exist..

Strange, works just fine for me in either the IDLE editor or the shell.

Ene Uran 638 Posting Virtuoso

wat is typo?

Slang for typing error!