Menu

Tkinter calls

2024-02-17
2024-02-17
  • David Goadby

    David Goadby - 2024-02-17

    I need to make a few direct Tkinter calls. Providing I keep them away from the "untouchable" files are there any restrictions? At first glance I didn't think so but it seems prudent to ask before starting the work.

    Oh, I have now upgrade to V8 and am much impressed! More donations will follow.

    I have to admit to doing a couple of quick projects using PySimpleGui. However, they have just altered their licencing model and it is $99/year if you want to monetize your software that uses it. I'm not averse to paying but the leap to $99 even before you know how many copies you might sell seems harsh. There is also a system of user registrations that adds complications if I create Windows .exe or Linux Appimage files. Glad to be back here ;-)

     
  • Greg Walters

    Greg Walters - 2024-02-17

    Hello David.
    First, allow me to thank you for signing in to Sourceforge. It certainly is easier to refer to a user's name rather than "Hello Anonymous". Doesn't have the same ring to it.

    Seconly, Thank you for the kind words about V8 and "comeing back to the fold". :o)

    Now to your question.
    I guess it really depends on what calls you need to make. PAGE uses the following command to start up when running the page.py file...

        root.tk.eval(cmd)
    

    where 'cmd' is

    cmd = "source {" + os.path.join(os.path.dirname(p), 'page.tcl') + "}"
    

    Basically starting page.tcl (Since PAGE is written in Visual Tcl) .

    When you use themes, In your gui.py file is the following function...

        try:
            colourchart23_support.root.tk.call("source", "./themes/notsodark.tcl")
        except:
            pass
    

    Which is python calling the tk function to load a theme.

    So, yes, there are many times we might want to call tk procs.

    One other example, from PAGE 7.6 is the show_color.py file located in the color_chart folder of the PAGE 7.6 distribution...

    root.tk.eval('set argv {}; set argc 0')
    p = os.path.abspath(sys.argv[0])
    cmd = "source {" + os.path.join(os.path.dirname(p), 'show-color.tcl') + "}"
    
    #print(f'{cmd=}')
    
    for a in sys.argv[1:]: # Skip argv[0] (the filename of this script)
        # root.tk.eval(f'lappend argv {{{a}}}; incr argc')
        root.tk.eval("lappend argv {%s}; incr argc" % a)
    
    try:
        root.tk.eval(cmd)
        sys.exit()
    except:
        pass
    

    as you can see, it uses the root.tk.eval to run the show-color.tcl file directly from Python.

    So it really depends on the tcl/tk code you really need to call.
    The best way to find out is to give it a try.

    Greg

    I hope this helps.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.