← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #462009]: Example of implementing a GUI for Sikuli

 

Question #462009 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/462009

    Status: Open => Solved

Maurice Richard confirmed that the question is solved:
I'm sure this could be cleaner, but this works ... in case it helps
others:

#Global Variable used to avoid glitch when calling functions by button click
varButtonClicked = "No"

#Function to use global variable to handle glitch with calling function on button click
def ProcessClick(event):
    global varButtonClicked
    varButtonClicked = 'Yes'

#Function to do 'whatever'
def DoSomething(event):
    #Code here to do whatever you want

#genrrates interface for the user
frame = JFrame("Some Title")
frame.setSize(200, 100)
frame.setLayout(BorderLayout())
label = JLabel('Some label text. ')
frame.add(label, BorderLayout.NORTH)
button = JButton('Button Text Here',actionPerformed=ProcessClick)
frame.add(button, BorderLayout.SOUTH)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setVisible(True)

#listener to handle button clicks
while True:
  if (varButtonClicked=='Yes'):
    global varButtonClicked    
    varButtonClicked = "No"      
    DoSomething()    
  wait(1)

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.