Tkinter root window problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhitam30111985
    New Member
    • Aug 2007
    • 112

    Tkinter root window problem

    hi all.. python noob here.. i am creating a GUI for an applcation... now i was just testing the working of askstring :
    [CODE=python]
    from tkSimpleDialog import askstring
    string=askstrin g('site','enter site:')
    print string
    [/CODE]

    now.. an extra empty window just pops up.. so i include NoDefaultRoot in th \e following manner:
    [CODE=python]
    from Tkinter import *
    NoDefaultRoot()
    from tkSimpleDialog import askstring
    string=askstrin g('site','enter site:')
    print string
    [/CODE]

    it then gives the following set of errors:
    Traceback (most recent call last):
    File "./check2.py", line 5, in ?
    string=askstrin g('site','enter site:')
    File "/usr/lib/python2.4/lib-tk/tkSimpleDialog. py", line 304, in askstring
    d = _QueryString(ti tle, prompt, **kw)
    File "/usr/lib/python2.4/lib-tk/tkSimpleDialog. py", line 282, in __init__
    _QueryDialog.__ init__(self, *args, **kw)
    File "/usr/lib/python2.4/lib-tk/tkSimpleDialog. py", line 172, in __init__
    parent = Tkinter._defaul t_root
    AttributeError: 'module' object has no attribute '_default_root'
    any idea whats wrog? or any alternative way to stop the default window from appearing?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    The first method is correct.

    The "extra" window is actually the application. It will eventually hold your main window. At this point, it is there to get all the event system, etc. rolling.

    Comment

    • rhitam30111985
      New Member
      • Aug 2007
      • 112

      #3
      yes but the problem still exists.. anyhow,, here is something else on similar lines:
      [CODE=python]
      from Tkinter import *
      from tkSimpleDialog import askstring
      win=Tk()
      ti={1:[2,4,5,6],3:[4,8,7,9,0],4:[5,5,6]}
      enter=askstring ('','')
      for tag,num in ti.items():
      if enter in num:
      Label(text=tag, width=20).pack( )
      win.mainloop()
      [/CODE]

      above program ideally should give me a window with 1 and 4 as its labels... but it gives an empty window... where am i going wrong?

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by rhitam30111985
        yes but the problem still exists.. anyhow,, here is something else on similar lines:
        [CODE=python]
        from Tkinter import *
        from tkSimpleDialog import askstring
        win=Tk()
        ti={1:[2,4,5,6],3:[4,8,7,9,0],4:[5,5,6]}
        enter=askstring ('','')
        for tag,num in ti.items():
        if enter in num:
        Label(text=tag, width=20).pack( )
        win.mainloop()
        [/CODE]

        above program ideally should give me a window with 1 and 4 as its labels... but it gives an empty window... where am i going wrong?
        Looks like
        • Label() needs a parent window
        • The only available window is win (not the dialog)
        • Label() text might need to be a string (str(tag)), but ints may get converted
        One way to get dictionaries to automatically make string type keys is:
        Code:
        dd = dict(1=[2,3,4])

        Comment

        • rhitam30111985
          New Member
          • Aug 2007
          • 112

          #5
          well ints do get converted in python V2.4.. also if i change line 8 to the following:
          Code:
          Label(win,text=tag,width=20).pack()
          which is unnecessary since it will use the default window ie win(ie Label wont need a parent window)... it still gives the same output

          what to do?

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by rhitam30111985
            well ints do get converted in python V2.4.. also if i change line 8 to the following:
            Code:
            Label(win,text=tag,width=20).pack()
            which is unnecessary since it will use the default window ie win(ie Label wont need a parent window)... it still gives the same output

            what to do?
            Sorry. I didn't see that IF statement in there:[CODE=python]
            from Tkinter import *
            from tkSimpleDialog import askstring
            win=Tk()
            ti={1:[2,4,5,6],3:[4,8,7,9,0],4:[5,5,6]}
            enter=askstring ('','')
            for tag,num in ti.items():
            Label(text=tag, width=20).pack( )
            win.mainloop()[/CODE]Works. I cant' imagine what you are attempting with:[CODE=python] if enter in num:[/CODE]

            Comment

            • rhitam30111985
              New Member
              • Aug 2007
              • 112

              #7
              ok here is a snippet of what i am actually working on:
              [CODE=python]
              import sys
              from Tkinter import *
              root = Tk()
              widget=Toplevel ()
              win2=Toplevel()
              sub=Listbox(wid get)
              sbar=Scrollbar( widget)
              sbar.config(com mand=sub.yview)
              sub.config(yscr ollcommand=sbar .set)
              sbar.pack(side= RIGHT,fill=Y)
              sub2=Listbox(wi n2)
              sbar2=Scrollbar (win2)
              sbar2.config(co mmand=sub2.yvie w)
              sub2.config(ysc rollcommand=sba r2.set)
              sbar2.pack(side =RIGHT,fill=Y)
              i=0
              wordlist=['qqe','rrt','yt gh','ihj']
              def enter():
              sub2.insert('en d',sub.curselec tion())
              sub2.pack()

              def writesub():
              global i
              sub.insert('end ',wordlist[i])
              i+=1
              if i==len(wordlist )-1:
              i=0
              sub.pack(expand =YES,fill=BOTH)
              mainbutton=Butt on(root,text="e nter text",command=w ritesub).pack(e xpand=YES,fill= BOTH)
              exitbutton=Butt on(root,text='Q UIT',command=sy s.exit).pack(fi ll=BOTH,expand= YES)
              enter()
              root.mainloop()
              [/CODE]
              now as i click the button " enter text" , the words in the wordlist get appended as expected in "sub" Listbox.. at the same time.. what i want is if i click any of the words in this list box.. it should get appended in the "sub2" listbox ... which is not happening ... it is just giving a blank window..

              Comment

              • rhitam30111985
                New Member
                • Aug 2007
                • 112

                #8
                i also added the following in line 19:
                [CODE=python]
                sub2.insert('en d',sub.get(sub. curselection()) )
                [/CODE]

                now the problem is that i have to click the button everytime i have to append the selected string in the sub list box in the sub2 listbox

                how do i get around it?

                Comment

                • rhitam30111985
                  New Member
                  • Aug 2007
                  • 112

                  #9
                  hey everyone .. never mind... problem solved.... didnt create a binding event with the double click...

                  Comment

                  Working...