-
-
Notifications
You must be signed in to change notification settings - Fork 33
Using AREPL with GUI's
You can use AREPL with graphical user interfaces (GUI's) like turtle and many others. Note that for certain libraries arepl automatically restarts so the visualization starts from fresh each time. To make this less annoying arepl automatically uses a longer delay after typing before restarting. The extra delay can be controlled in the settings. Or you can switch to execute on save/keybinding.
I suggest coding it so the gui appears on the side (not blocking your view of your code), like so:
import turtle
turtle.setup(width=500, height=500, startx=-1, starty=0)
# turtle.reset()
# uncomment above if you want turtle to reset each time
turtle.forward(100)
turtle.left(90)
Note that the GUI might steal focus from vscode, so if you do not already know it I highly suggest memorizing the shortcut to switch focus back to the previous application. (alt-tab on windows, command-tab on mac)
With PySimpleGui you can use the location parameter to control where the window appears:
import PySimpleGUI as sg
# 0,0 is top left
startx = 1000 # A higher value will make the window appear more on the right side of the screen
starty = 0
# window layout - see PySimpleGui documentation for more info
layout = [[sg.Text('Input:')], [sg.Input()], [sg.OK(), sg.Cancel()]]
# spawn the window
event, (input,) = sg.Window('Title', location=(startx,starty)).Layout(layout).Read()
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 50])
plt.ylabel('some numbers')
mngr = plt.get_current_fig_manager()
mngr.canvas.manager.window.wm_geometry("+1200+0") #right-hand side
plt.show()
depends on the backend used - if this doesn't work see this stackoverflow