tkinter text editor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gigs_

    #1

    tkinter text editor

    I'm writing text editor.

    How to enable/disable (cut, copy etc.) when text is selected/not selected
  • Gigs_

    #2
    Re: tkinter text editor

    Gigs_ wrote:
    I'm writing text editor.
    >
    How to enable/disable (cut, copy etc.) when text is selected/not selected
    Btw it is cut copy ... in edit menu

    Comment

    • jim-on-linux

      #3
      Re: tkinter text editor

      On Friday 09 March 2007 12:04, Gigs_ wrote:
      Gigs_ wrote:
      I'm writing text editor.

      How to enable/disable (cut, copy etc.) when
      text is selected/not selected
      >
      Btw it is cut copy ... in edit menu

      state = 'diabled' ## no change allowed
      ## to Text Wiget

      state = 'normal' ## default for Text Wiget

      jim-on-linux
      http:\\www.inqvista.com

      Comment

      • Gigs_

        #4
        Re: tkinter text editor

        jim-on-linux wrote:
        On Friday 09 March 2007 12:04, Gigs_ wrote:
        >Gigs_ wrote:
        >>I'm writing text editor.
        >>>
        >>How to enable/disable (cut, copy etc.) when
        >>text is selected/not selected
        >Btw it is cut copy ... in edit menu
        >
        >
        state = 'diabled' ## no change allowed
        ## to Text Wiget
        >
        state = 'normal' ## default for Text Wiget
        >
        jim-on-linux
        http:\\www.inqvista.com
        yes man but i want to make that when there is no selected text this menu
        items go DISABLED and when text is selected this menu items go NORMAL

        Comment

        • James Stroud

          #5
          Re: tkinter text editor

          Gigs_ wrote:
          jim-on-linux wrote:
          >
          >On Friday 09 March 2007 12:04, Gigs_ wrote:
          >>
          >>Gigs_ wrote:
          >>>
          >>>I'm writing text editor.
          >>>>
          >>>How to enable/disable (cut, copy etc.) when
          >>>text is selected/not selected
          >>>
          >>Btw it is cut copy ... in edit menu
          >>
          >>
          >>
          >state = 'diabled' ## no change allowed
          > ## to Text Wiget
          >state = 'normal' ## default for Text Wiget
          >>
          >jim-on-linux
          >http:\\www.inqvista.com
          >
          yes man but i want to make that when there is no selected text this menu
          items go DISABLED and when text is selected this menu items go NORMAL
          You have to methodically determine on an event by event basis what is
          going to cause selection and what isn't, then update the menus
          accordingly. It takes a lot of testing. An alternative is polling
          whether text is selected at the moment but is a waste of CPU cycles and
          is unnecessary.

          Best is to let the system clipboard handle copy-paste as it was designed
          to do. You are opening a can of worms trying to micromanage your
          application.

          James

          Comment

          • John McMonagle

            #6
            Re: {Possible_Spam} tkinter text editor

            Gigs_ wrote:
            I'm writing text editor.
            >
            How to enable/disable (cut, copy etc.) when text is selected/not selected

            Bind the Button1-ButtonRelease event to a function which checks the
            length of the SEL tag of the text widget. If it is zero length, disable
            the appropriate menu entries, if it is non-zero, enable the appropriate
            menu entries.

            Simple example:


            from Tkinter import *
            root = Tk()

            textWidget = Text(root)
            textWidget.pack ()

            def onButton1Releas e(event):
            if len(textWidget. tag_ranges(SEL) ) == 0:
            print 'No text selected. Disable appropriate menu entries'
            else:
            print 'Some text selected. Enable appropriate menu entries'

            textWidget.bind ('<Button1-ButtonRelease>' , onButton1Releas e)

            root.mainloop()

            Comment

            • John McMonagle

              #7
              Re: {Possible_Spam} Re: {Possible_Spam} tkinter text editor


              ---------- Original Message -----------
              From: Gigs <gigs@hi.t-com.hr>
              To: John McMonagle <jmcmonagle@vel seis.com.au>
              Sent: Sat, 10 Mar 2007 15:13:20 +0100
              Subject: {Possible_Spam} Re: {Possible_Spam} tkinter text editor
              John McMonagle wrote:
              Gigs_ wrote:
              I'm writing text editor.
              >
              How to enable/disable (cut, copy etc.) when text is selected/not
              selected

              Bind the Button1-ButtonRelease event to a function which checks the
              length of the SEL tag of the text widget. If it is zero length,
              disable the appropriate menu entries, if it is non-zero, enable the
              appropriate menu entries.

              Simple example:


              from Tkinter import *
              root = Tk()

              textWidget = Text(root)
              textWidget.pack ()

              def onButton1Releas e(event):
              if len(textWidget. tag_ranges(SEL) ) == 0:
              print 'No text selected. Disable appropriate menu entries'
              else:
              print 'Some text selected. Enable appropriate menu entries'

              textWidget.bind ('<Button1-ButtonRelease>' , onButton1Releas e)

              root.mainloop()
              thx, but what i dont know is how to change state on menu item.
              I dont know how to access that menu item later.
              I know on button like
              B = Button(root)
              B.pack()
              >
              and later i change with B.config(blabla )
              >
              but on menu i have more items like
              M = Menu(root)
              i.add_command(l abel='one', command=show1)
              i.add_command(l abel='two', command=show2)
              M.add_cascade(l abel='File', menu=i)
              >
              how to change item: 'two'
              >
              Use the entry config method of the Menu widget:

              i.entryconfig(' one', state=DISABLED)

              Here is some recommended reading:

              http://www.pythonware.com/library/tk...41-methods.htm


              Comment

              Working...