GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Aug-2006, 08:22
ash.shuklaa ash.shuklaa is offline
New Member
 
Join Date: Aug 2006
Posts: 5
ash.shuklaa is on a distinguished road

Python/Tk GUI


Hi,

I am making a GUI with the help of python. The problem is that when I destroy a certain frame the data structure assciated with it, does'nt change. Can anybody offer any help on this?

I have attached the program and it would be great if anybody can offer some useful suggestions.
Attached Files
File Type: txt note.txt (2.0 KB, 20 views)
  #2  
Old 30-Aug-2006, 12:56
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Python/Tk GUI


Well, I get the following error when I click the "Add" button. Do you?
Quote:
File 'temp.py', line 58, in delete_frame
del frame_2.sub_frame[str(temp)]
TypeError: list indices must be integers

Basically what's happening with this error is that this line
Quote:
del frame_2.sub_frame[str(temp)]
is trying to make a list but you're casting the temp value into a string and Python doesn't like that, at least how it's implemented here.

What exactly is this program supposed to be doing?
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #3  
Old 30-Aug-2006, 13:45
ash.shuklaa ash.shuklaa is offline
New Member
 
Join Date: Aug 2006
Posts: 5
ash.shuklaa is on a distinguished road

Re: Python/Tk GUI


Hi,

I apologise for posting the file I was playing with, I am attaching the program in working condition and when u press the "ADD" button new frames will build up and when u press "delete button those frames will be destroyed ". My problem is that these frames only get destroyed in Tk not in python's data structure.

Kindly try again.

Regards
Ash
-------------------------------------------------------------------------
Python Code:
#!/usr/bin/python
from Tkinter import*

class Frame_1(LabelFrame):
    def __init__(self,master):
        LabelFrame.__init__(self,master)
        self.configure(text="Frame1")
        self.grid()     
        
    def control_buttons(self,frame):
        Button( self, text = "Add", command = frame.add_button ).grid( ) 
        Button( self, text = "Read", command = frame.read_button ).grid()
        
class Frame_2(LabelFrame):
    def __init__(self,master):
        LabelFrame.__init__(self,master)
        self.configure(text ="Frame2")
        self.grid()
        self.sub_frame = []
        
    def add_button(self):        
        new_frame = Frame_2_1(self)
       # new_frame.grid()        
        new_frame.populate()
        self.sub_frame.append(new_frame)
      #  print self.sub_frame
        
    def read_button(self):
        print "#"*10 
        for sub_frame in self.sub_frame :
            print "-"*30
            print "band:"+ sub_frame.band.get()
            print "channel:" + sub_frame.channel.get()
            
class Frame_2_1(LabelFrame):
    def __init__(self,tkmaster):
        LabelFrame.__init__(self,tkmaster)
        self.configure(text ="DEFAULT")
        self.grid()
        
    def populate(self): 
        self.band = StringVar()
        self.band.set("900")
        option = OptionMenu(self, self.band,"900","1800","1900" ).grid()
     
        self.channel = StringVar()
        self.channel.set("CS 1") 
        option = OptionMenu(self,self.channel,"CS 1","CS 2","CS 3","CS 4").grid( )

        global temp
        temp= temp+1
        Button(self,text = "Remove"+ str(temp),command= self.delete_frame).grid()

    
    def delete_frame(self):
        self.destroy()
        
root = Tk()
temp=-1
# Create frame 1
frame_1 =  Frame_1(root)
# Create frame 2 
frame_2 = Frame_2(root)

frame_1.control_buttons(frame_2)  
root.mainloop()
--------------------------------------------------------------------------
attachments weren't working


Quote:
Originally Posted by crystalattice
Well, I get the following error when I click the "Add" button. Do you?


Basically what's happening with this error is that this line is trying to make a list but you're casting the temp value into a string and Python doesn't like that, at least how it's implemented here.

What exactly is this program supposed to be doing?
Last edited by cable_guy_67 : 31-Aug-2006 at 14:07. Reason: Please surround your Python code with [py] your code [/py]
  #4  
Old 31-Aug-2006, 14:06
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Python/Tk GUI


Not to sound lazy, but could you try again using [py][/py] around your code? It will keep the indents in your code (plus highlight it appropriately). I tried working with your code but I'm not sure where the indents are supposed to be.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
Last edited by cable_guy_67 : 31-Aug-2006 at 14:08. Reason: Added [noparse] around [py]
  #5  
Old 31-Aug-2006, 14:23
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Python/Tk GUI


Thanks for the fix, cable buddy.

Ash, try adding
Python Code:
self.channel.set("")
self.band.set("")
to your delete_frame method. I'm not sure if it's what you want, but it keeps the data from being written out when you close the frames.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #6  
Old 01-Sep-2006, 10:34
ash.shuklaa ash.shuklaa is offline
New Member
 
Join Date: Aug 2006
Posts: 5
ash.shuklaa is on a distinguished road

Re: Python/Tk GUI


Thanks crystal but that doesnt solve the purpose. I need to alter the list (sub_frame).

It might mean that I need to develop my data structure from scratch every time i press "remove"
  #7  
Old 02-Sep-2006, 11:49
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Python/Tk GUI


I'm confused. If I'm reading your code correctly, every time the "ADD" button is pressed a new frame is added to the sub_frame list. Each sub_frame then has the band and channel choices available.

Now, when the sub_frame is removed, do you want to keep the data that sub_frame and print it out or do you want the data deleted along w/ the frame?
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #8  
Old 02-Sep-2006, 12:12
ash.shuklaa ash.shuklaa is offline
New Member
 
Join Date: Aug 2006
Posts: 5
ash.shuklaa is on a distinguished road

Re: Python/Tk GUI


When the sub_frame is removed (destroyed), I want the data associated with it destroyed as well [which I think means updating that sub_frame list.]

Thanks for the help.





Quote:
Originally Posted by crystalattice
I'm confused. If I'm reading your code correctly, every time the "ADD" button is pressed a new frame is added to the sub_frame list. Each sub_frame then has the band and channel choices available.

Now, when the sub_frame is removed, do you want to keep the data that sub_frame and print it out or do you want the data deleted along w/ the frame?
  #9  
Old 02-Sep-2006, 17:33
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Python/Tk GUI


Well, I'd imagine that you need to do something directly to the sub_frame when you call delete_frame. I'm not sure what you may want to do, but you could slice off the last entry, use the del method, or another way to remove the entries from the list.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #10  
Old 02-Sep-2006, 18:21
ash.shuklaa ash.shuklaa is offline
New Member
 
Join Date: Aug 2006
Posts: 5
ash.shuklaa is on a distinguished road

Re: Python/Tk GUI


Quote:
Originally Posted by crystalattice
Well, I'd imagine that you need to do something directly to the sub_frame when you call delete_frame. I'm not sure what you may want to do, but you could slice off the last entry, use the del method, or another way to remove the entries from the list.

thats the problem, i need to keep a trace of pointers. It is possible with if I can somehow relate every delete method back to its pointer and than update list. For that I assume i need to add arguements to my object to trace it....how i am gonna do it...thats what i dont know

thanks for the help....
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:14.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.