Using tkinter with pythonscad

7 views
Skip to first unread message

Dylan

unread,
Jul 5, 2025, 10:50:43 AMJul 5
to pytho...@googlegroups.com
Hello,

I am developing a pythonSCAD program to model medieval wind instruments
so I can make bespoke cases for them. An instrument is described by one
or more lists of measurements which can amount to 50 or more entries.

Currently, I am entering the measurements into a spreadsheet, saving it
as a csv file, and reading that csv file into my program. This is
functional, but inconvenient, not least because locating an error in the
measurements is difficult and the csv file has to include ancillary
information relating to how the file is to be parsed.

I thought it may be possible to use a TK interface so that a preview
could be generated dynamically during entry of the measurements.
However, running the minimal test, below, I find that, although clicking
on the button in the the TK window functions correctly, the cube is not
previewed until the TK window is closed. If the button is clicked
multiple times then multiple cubes are rendered as expected. Also, if
there is a bug in the click() handler (omitting the 'nonlocal shift', in
this case) the error is reported when the window closes.

Am I asking too much of the system, or is there a way to get this working?

Thanks,

Dylan

from openscad import *
import tkinter as tk
def doit():
    shift = 0

    def click(event):
        nonlocal shift
        show(cube(5).right(shift))
        shift += 10

    window = tk.Tk()
    btn=tk.Button(text="TEST")
    btn.bind("<Button-1>",click)
    btn.pack()
    window.mainloop()

doit()

Guenther Sohler

unread,
Jul 5, 2025, 11:06:15 AMJul 5
to Dylan, PythonSCAD
Your Problem IS that tkinter IS blocking and No PythonSCAD and tkinter can Provide the GUI at the Same time.

But you can Turn PythonSCAD into a non GUI pip package instead. IT will only offer funnctionality and Display could Work with an external stl Viewer or maybe a TK Widget.
To so so Compile this with:
python setup.py build.
The File ist found in the Root directory of the git repo.
Keep US updated about your Progress!

--
You received this message because you are subscribed to the Google Groups "PythonSCAD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonscad+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/pythonscad/e1c2a6f7-5d42-4301-9dd6-b82868f13948%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

Guenther Sohler

unread,
Jul 5, 2025, 11:09:15 AMJul 5
to Dylan, PythonSCAD
Another Option IS to to Use the openscad customizer to Input your Data. Its Not tkinter but another graphical input Option.

Dylan

unread,
Jul 5, 2025, 11:13:08 AMJul 5
to Guenther Sohler, PythonSCAD, rabbi...@googlemail.com
Thank you. I thought that might be the case.

I'll look in to your suggestion tomorror.

Dylan
> <mailto:pythonscad%2Bunsu...@googlegroups.com>.

Dylan

unread,
Jul 6, 2025, 7:25:53 AMJul 6
to Guenther Sohler, PythonSCAD, rabbi...@googlemail.com
I think I'll be abandoning this idea - after spending all morning
installing various libraries and utilities on my test machine, I reach
the following missing library.

In file included from src/core/OffsetNode.cc:27:
src/core/OffsetNode.h:5:10: fatal error: clipper2/clipper.h: No such
file or directory
    5 | #include "clipper2/clipper.h"
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.

clipper2 is not available from my distribution repositories, and
although I've found what I think is the correct library in github,
compilation and installation instructions are lacking and since it's
been 20+ years since I needed to compile anything outside of a small
personal project in an IDE this is a full stop for me.

I can't justify spending hours (days? weeks?) trying to get this to
work, so I'll simply continue importing a csv file into my script.

Using the Customizer looks like a non-starter because of the number and
variety of measurements.

Dylan

On 05/07/2025 16:06, Guenther Sohler wrote:
> <mailto:pythonscad%2Bunsu...@googlegroups.com>.

William Adams

unread,
Jul 7, 2025, 7:03:51 AMJul 7
to PythonSCAD
I've been wanting more interactivity and better customization than the Customizer affords, so this is very interesting to me (esp. see recent discussions of adding UI elements in the 3D view).

That said, there is a lot of power in the Customizer, esp. note the ability to divide things up by tabs --- if nothing else, you could work things up using that, but use the .csv as an optional interface.

Did you try setting up PythonSCAD for "Instant Reload" mode? That should allow you to:

 - launch your GUI program using "normal" Python
 - write out a file from it
 - load that file into PythonSCAD and have it render
 - make a change and write out a new file from the GUI program
 - PythonSCAD will then re-render the design when it sees the underlying program has changed

I'm surprised you were able to bring up a second window using PythonSCAD --- thanks for letting me know that it's possible!

William

Guenther Sohler

unread,
Jul 7, 2025, 7:19:31 AMJul 7
to William Adams, PythonSCAD
Yes, More Interactivity is great

I have once added an option to define custom dropdown menu items and callbacks especially usable for gcodepreview,
But they are neither not yet used  nor documented or recently tested. 
This would allow  to start python magic not with F5/F6, but from the File Menu e.g.

I am happy to extend the customizer, if this allowed for a way more versatile input, but before to progress there, we need a way more versatile input  concept.

Yes, many Libraries are available als a python module. So is tkinter . and tkinter is a graphical GUI library,  which can be used with
any python script.
Its just not so applicable with pythonscad because it has a GUI already.
GUI libraries depend on a main blocking event loop and having  two of them in parallel will not work out..

PS: the second window is from tkinter and yes, its possible . its just not  so usable because pythonscad will freeze until the inner gui has quit.





To unsubscribe from this group and stop receiving emails from it, send an email to pythonscad+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/pythonscad/dcb85a3b-fd2d-4ab6-93da-dbb743af3b81n%40googlegroups.com.

Dylan

unread,
Jul 7, 2025, 7:30:48 AMJul 7
to pytho...@googlegroups.com
"PS: the second window is from tkinter and yes, its possible . its just
not  so usable because pythonscad will freeze until the inner gui has quit."

Would it be possible to have a call-back function which when called from
an inner GUI would trigger the main GUI to process any pending
events/function calls before returning control to the calling program?
In e.g. QT there is a ProcessEvents() method which a dialog can call to
have to main window react to changes without needing to close the dialog.
Dylan
> <https://groups.google.com/d/msgid/pythonscad/dcb85a3b-fd2d-4ab6-93da-dbb743af3b81n%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google
> Groups "PythonSCAD" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pythonscad+...@googlegroups.com.
> To view this discussion, visit
> https://groups.google.com/d/msgid/pythonscad/CAASeUHoJfdDy4eTfugMV82nEqjLax1YEAu69OhzrZ7_rRpBBcQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/pythonscad/CAASeUHoJfdDy4eTfugMV82nEqjLax1YEAu69OhzrZ7_rRpBBcQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Guenther Sohler

unread,
Jul 7, 2025, 8:00:49 AMJul 7
to Dylan, pytho...@googlegroups.com
I have actually found the processEvent() call and I could expose it as a python function.

But even if it worked, it would lead to very bad programming style and I think i would not trade it, unless we get a really exciting feature out of it.

But it will not work even if we use processEvents.
PythonSCAD GUI does not actually lock because of the inner GUI's main loop, but because python is run in an extra thread and
PytonSCAD main function is waiting for python code to finish.

I have done this because some python code requires quite some time to execute and I wanted  the main window to stay reactive in the meantime.m 
I can do some tests still, but I think even there was a 10 sec delay in the code, pythonscad main window should  stay quite reactive.
And even your inner GUI should be actually more alive than expected. 
I can probably test the code again and evaluate to find out why it actually does not match your expectation.


Reply all
Reply to author
Forward
0 new messages