Пример #1
0
    def __init__(self, **kargs):
        """Creates a new application with some standard menus and such
        Returns the root window, just like Tk()
        To use:
            import RO.Wdg
            myApp = RO.Wdg.PythonTk()
            # configure stuff here, e.g. creating new windows, etc.
            myApp.mainloop()

        Keyword arguments:
            All those for Tkinter.Tk(), plus:
            "optionfile": the full path name of an option file
        """

        # first parse PythonTk-specific options
        # but do not try to apply them yet if they require Tk to be initialized
        optionfile = None
        if kargs and kargs.has_key("optionfile"):
            optionfile = kargs["optionfile"]
            del(kargs["optionfile"])

        # basic initialization
        Tkinter.Tk.__init__(self, **kargs)
        
        # if the user supplied an option file, load it
        if optionfile:
            try:
                self.option_readfile(optionfile)
            except Exception as e:
                print("cannot read option file; error:", e)
        
        # create and display a Python script window
        self.pyToplevel = Tkinter.Toplevel()
        self.pyToplevel.geometry("+0+450")
        self.pyToplevel.title("Python")
        pyFrame = PythonWdg.PythonWdg(self.pyToplevel)
        pyFrame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)
        
        # set up standard bindings
        Bindings.stdBindings(self)
Пример #2
0
    wdg.__ctxMenu = CtxMenu(
        wdg=wdg,
        helpURL=helpURL,
        configFunc=configFunc,
        doTest=doTest,
    )
    return wdg.__ctxMenu


if __name__ == "__main__":
    import Bindings
    import PythonTk
    root = PythonTk.PythonTk()

    # set up standard binding for <<CtxMenu>>
    Bindings.stdBindings(root)

    # add help to a standard Tkinter widget
    stdLabel = Tkinter.Label(text="Standard label")
    addCtxMenu(
        wdg=stdLabel,
        helpURL="http://brokenURL.html",
    )
    stdLabel.pack()

    # create a new label class that automatically has help:
    class HelpLabel(Tkinter.Label, CtxMenuMixin):
        def __init__(self, master, helpURL=None, **kargs):
            Tkinter.Label.__init__(self, master=master, **kargs)
            CtxMenuMixin.__init__(self, helpURL)