In the attached script I want to keep the form active for additional instances of drawing the circle. At present when I click OK the form closes and the prompt asks for a point then draws the circle. I want the form to return as active for another circle until I press the cancel button.
I am a newbie to Python and GUI and looking for help understanding basics. Study indicates it has something to do with main but I am unclear how to manage this structure.
Is it even possible to achieve this? I am surprised at the lack of help with this question. Is it too basic to be interesting? I have tried a variety of strategies including OnClick inside and outside the class but the form always closes and needs to be rerun.
Is there a good primer on how to hook up Winforms to scripting?
if __name__ == "__main__":
bool = True
while bool:
form = CirForm()
if form.ShowDialog() == System.Windows.Forms.DialogResult.OK:
rs.AddCircle(rs.GetPoint(), form.radius)
else:
bool = False
Iām not a python expert but this should work
This creates a boolean (True or False) and continues to rerun the same part of the script until the bool = False
If you press Ok in the form it returns the System.Windows.Forms.DialogResult.OK. If you click Cancel you get a System.Windows.Forms.DialogResult.Cancel. So when anything else comes up than a OK it changes the bool = False and the while loop stops.
If you put the form = CirForm() before the while bool: then it keeps the size of your previous circle like this:
if __name__ == "__main__":
bool = True
form = CirForm()
while bool:
form.CenterToScreen()
if form.ShowDialog() == System.Windows.Forms.DialogResult.OK:
bool = True
rs.AddCircle(rs.GetPoint(), form.radius)
else:
bool = False
Many thanks for this - it works perfectly. I am going to play around with this a bit but it is clear that I need more understanding of " if name == āmainā: ".
I have been searching on this for a while and find the results not very satisfying. Any good references that you know of?
If you are looking to learn the basics of python you can check:
scroll down a bit and click on python. Then you get to learn python from the start. Defining variables. Making functions and if statements / loops. It lets you make assignments before you can continue so you really learn it there by doing it