pyxforms/examples/demo3.py

78 lines
1.2 KiB
Python
Executable File

#!/usr/local/bin/python
from Pyxform import *
from goodies import *
#
# Init the library (sucks but works)
#
xfinit("Something", "1", sys.argv[0])
#
# Create a "Window" - A form in XForms parlance
win = Form()
#
# Show it
win.Show()
#
# Create a button, and 2 sliders
a_button = Button(0, 10, 10, 100, 30, "Press Me")
h_slider = Slider(5, 0, 180, 200, 20, "")
v_slider = Slider(4, 180, 0, 20, 180, "")
#
# Set some values for the sliders
h_slider.Setbounds(0, 200)
h_slider.Set(0)
v_slider.Setbounds(0, 200)
v_slider.Set(0)
#
# Put them inside win
win.Add(a_button)
win.Add(h_slider)
win.Add(v_slider)
#
# Define a function, that will be executed when the button is pressed
def funct(self):
# It shows a message and exits (or not)
answer = show_question("Do you want", "to exit?", "")
if answer == 1:
sys.exit()
#
# And another one, for when the sliders move
def slide(self):
# It moves the button to the position of the sliders
a_button.x = h_slider.Get()
a_button.y = v_slider.Get()
#
# And bind the functions to the controls
a_button.cb = funct
h_slider.cb = v_slider.cb = slide
#
# Start the event loop
# It will run until you press the button and say yes
runforms()