the second of nested buttons using textvariable remains void!

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

    the second of nested buttons using textvariable remains void!

    Hi there,

    I am fighting with a problem I intended to believe trivial that
    I could not solve yet!

    I am trying to have a button with a variable text, that
    pops up another button with a variable text when pressed.

    I did that with the following program in Python, but the
    second button remains always void!!! is it related to
    the textvariable parameters?

    If any of you had a clue, please don't hesitate!

    in advance, many thanks

    Samuel

    #----------------------- program 2 buttons.py
    --------------------------

    from Tkinter import *


    def go(event):
    root = Tk()

    s1=StringVar()
    s1.set("s1")
    label1 = Label(root, textvariable=s1 )
    label1.pack(sid e=LEFT)

    root.mainloop()



    root = Tk()

    s0=StringVar()
    s0.set("s0")
    label0 = Label(root, textvariable=s0 )
    label0.pack(sid e=LEFT)


    root.bind("<Ret urn>",go)

    root.mainloop()

  • James Stroud

    #2
    Re: the second of nested buttons using textvariable remains void!

    Samkos wrote:
    Hi there,
    >
    I am fighting with a problem I intended to believe trivial that
    I could not solve yet!
    >
    I am trying to have a button with a variable text, that
    pops up another button with a variable text when pressed.
    >
    I did that with the following program in Python, but the
    second button remains always void!!! is it related to
    the textvariable parameters?
    >
    If any of you had a clue, please don't hesitate!
    >
    in advance, many thanks
    >
    Samuel
    >
    #----------------------- program 2 buttons.py
    --------------------------
    >
    from Tkinter import *
    >
    >
    def go(event):
    root = Tk()
    >
    s1=StringVar()
    s1.set("s1")
    label1 = Label(root, textvariable=s1 )
    label1.pack(sid e=LEFT)
    >
    root.mainloop()
    >
    >
    >
    root = Tk()
    >
    s0=StringVar()
    s0.set("s0")
    label0 = Label(root, textvariable=s0 )
    label0.pack(sid e=LEFT)
    >
    >
    root.bind("<Ret urn>",go)
    >
    root.mainloop()
    >

    You have instantiated Tk twice which causes these kind of problems. If
    you want a window in go(), use Toplevel instead of Tk (and "mainloop" is
    not needed in go()). I.e.:


    def go(event):
    not_root = Toplevel()

    s1=StringVar()
    s1.set("s1")
    label1 = Label(not_root, textvariable=s1 )
    label1.pack(sid e=LEFT)

    James

    Comment

    • jim-on-linux

      #3
      Re: the second of nested buttons using textvariable remains void!

      On Wednesday 21 March 2007 20:11, Samkos wrote:
      Hi there,
      >
      I am fighting with a problem I intended to
      believe trivial that I could not solve yet!
      >
      I am trying to have a button with a variable
      text, that pops up another button with a
      variable text when pressed.
      >
      I did that with the following program in
      Python, but the second button remains always
      void!!! is it related to the textvariable
      parameters?
      >
      If any of you had a clue, please don't
      hesitate!
      >
      in advance, many thanks
      >
      Samuel
      >
      #----------------------- program 2 buttons.py
      --------------------------
      >
      from Tkinter import *
      >
      >
      def go(event):
      root = Tk()
      >
      s1=StringVar()
      s1.set("s1")
      label1 = Label(root, textvariable=s1 )
      label1.pack(sid e=LEFT)
      >
      root.mainloop()
      >
      >
      >
      root = Tk()
      >
      s0=StringVar()
      s0.set("s0")
      label0 = Label(root, textvariable=s0 )
      label0.pack(sid e=LEFT)
      >
      >
      root.bind("<Ret urn>",go)
      >
      root.mainloop()
      try this;

      def go():
      root = Tk()
      root.config(bg= 'yellow')
      s1=StringVar()
      blabel1 = Button(root, textvariable=s1 ,
      width = 10, height = 2,
      command = next)
      blabel1.pack()
      root.bind("<Ret urn>", vbind)
      s1.set('click_s 1')

      def vbind(event):
      next()

      def next():
      second = Toplevel()
      s0=StringVar()
      s0.set("click_s 0")
      blabel0 = Button(second, textvariable=s0 ,
      command = second.destroy,
      width = 10, height = 2)
      blabel0.pack()

      if __name__ == '__main__' :
      go()
      mainloop()


      jim-on-linux

















      Comment

      • Samkos

        #4
        Re: the second of nested buttons using textvariable remains void!

        Thanks a lot Jim and James

        now it works fine!

        Sam

        Comment

        Working...