Thanks for the code on SwingUtilities; it’s a lot easier than I ever thought it would be, but that’s the ‘Python way’. Your code runs ok in Thonny. What’s up with using underscores in the actionEvents? I have seen myBtnAction(event) used, but not an underscore. The following demo is a modification of my original post to use an EventDispatchThread; I prefer to use ‘Import mode for py5’ to avoid having to use prefixes. It’s more like regular Processing code that way.
# Uses Imported mode for py5
from javax.swing import *
from java.awt import *
_wndW = 600
_wndH = 660
myColor = Color.GREEN
slider = JSlider()
def myBtnAction(event):
global myColor
panel = JPanel()
myColor = JColorChooser.showDialog(panel,"Choose color",Color.GREEN)
def buildWnd():
global slider
slider = JSlider(JSlider.HORIZONTAL, 0, 500, 100)
slider.setBounds(180, 20, 200, 24)
slider.setToolTipText("size");
frame.add(slider)
slider.repaint()
btn = JButton("Color")
btn.setBounds(400,20,80,24)
frame.add(btn)
btn.repaint()
btn.addActionListener(myBtnAction)
def setup():
global frame
size(_wndW, _wndH)
wnd = get_surface()
canvas = wnd.get_native()
frame = canvas.getFrame()
wnd.set_title('Default Processing Window')
canvas.setBounds(0,60,_wndW,_wndH - 60)
SwingUtilities.invokeLater(buildWnd)
def draw():
background(209)
fill(myColor.getRed(), myColor.getGreen(), myColor.getBlue())
circle(300,300,slider.getValue())