Newbie wxSlider questions.

Hi Scott,

Hi Robin and All,

I'm new to Python and wxPython but am enjoying working with both. I'm using the
latest ActivePython 2.5 and wxPython 2.8.7.1 on Windows 2000.

I want to make a simple application to do some simple calculations based on the
value from a wxSlider. The code below is my effort thus far. It has some
refreshing issues when the values in the static text boxes are updated. For
example, the value of the "thumb" in the slider control updates continuously as
the thumb is dragged to new values, but the values in the text boxes usually
update later. In addition, the values in the text boxes seem to cycle through
lower values until they reach the final value.

The slider seems to be the ideal control for this application, but I've been
unable to find real sample code that does something similar to what I'm trying
to do. I would like the values in the static text boxes to be updated smoothly
and continuously as the slider is moved with the arrow keys or the mouse.

I assume the problem is with the code as it behaves on other PCs with different
graphics cards, etc.

Here's my code. I appreciate any pointers, suggestions, or corrections you can
offer. Please be verbose as I'm a newbie. Thanks very much!

Uhm, let's see:

1) Every time your slider moves, you re-create from scratch the
wx.TextCtrl in your dialog, without destroying the old ones. You
shouldn't do that, you should create your wx.TextCtrl in the __init__
method of your dialog and change their values using SetValue() in the
slider event. See the attached file for this;

2) Do not use absolute positioning and sizing: use sizers. I know that
for newbies sizers might be a bit intimidating, but once you get a
grasp of them you will never need anymore to bother about widget
positions and sizes (unless you are doing something strange :smiley: ).
Plus your GUI will look nice on all platforms and (almost) all screen
resolutions at the first try. Please see the following Wiki pages for
an introduction:

http://wiki.wxpython.org/UsingSizers
http://wiki.wxpython.org/ChallengeSizers
What Do These Sizer Things Do? [in C++, but visually nice]

3) If you can, while your are at the beginning in your use of
wxPython, you should familiarize yourself with the wxPython Style
Guide:

http://wiki.wxpython.org/wxPython_Style_Guide

Which will renderyour code nicer, easier to maintain and easier to
understand by others (i.e. us) when you post some code that is not
doing what you want it to do.

HTH.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

prova109.py (4.92 KB)

ยทยทยท

On Jan 22, 2008 3:21 AM, D. Scott Katzer wrote:

Hi Andrea and Mike,

Thank you both very much for your pointers and suggestions. They are
very helpful, indeed.

I especially appreciate the corrected code you provided in the
attachment, Andrea. If I'm able to make the code more compliant with
the style guide, etc., would you object if I posted it in the Cookbook
wiki? http://wiki.wxpython.org/wxPython_Cookbook It might save other
newbies some time in trying to figure out how to use Sliders. I would
certainly give you credit and praise. :slight_smile:

I didn't look closely at the PyColourChooser example because the
source code was so short. Thanks for pointing it and the
AdjustChannels code out, Mike. I appreciate it and will look them
over again.

Cheers,
Scott.