Friday, September 25, 2015

Update Value using Slider in Visual Python

 Here's the code.
 The slider act as..., well..., slider... to change the value on TextCtrl. On slight modification, it'll able to change any variable value.

from __future__ import division, print_function
from visual import *
import wx

L = 400
H = 200
d = 20

def setrate(evt):
    value = s1.GetValue()
    tc.write('kecepatan = '+ str(value)) #mengeset kecepatan sesuai slider

w = window(width=2*(L+window.dwidth), height=L+window.dheight+window.menuheight+H,
           menus=True, title='Widgets',
           style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)

p = w.panel

tc = wx.TextCtrl(p, pos=(1.4*L,90), value='Tulisan\n',
                 size=(150,90), style=wx.TE_MULTILINE)

s1 = wx.Slider(p, pos=(1.0*L,0.8*L), size=(0.9*L,20), minValue=0, maxValue=100)
s1.Bind(wx.EVT_SCROLL, setrate)
wx.StaticText(p, pos=(1.0*L,0.75*L), label='kecepatan')

#standart mantra for vpython#
while True: