LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2015, 06:45 AM   #1
srinietrx
Member
 
Registered: May 2013
Posts: 101

Rep: Reputation: Disabled
Python tkinter, problem when using pack_forget to remove widget


Hi
I am C++ programmer new to Python.Developing graphical application using Tkinter.
As shown in screenshot
I programmed in such a way that when I press MC_CONFIG button new frame will open.
Inside that I am giving path using XML PATH button
opening and reading xml using MC_SYSTEM.xml button
After editing I gave two options

1--> OK (when Ok is pressed file is opened,xml parameters are written(we can edit) and closed with message"configuration file written successfully"
2--> Cancel(Ideally I want only the widget window where I am adding xml values need to be closed as shown in attachment.For that I used self.pack_forget()and it removes the widget and works.But when I go back and again click the button MC_CONFIG it is not opening.
Please guide me.

Code for On OK
Code:
def onOK(self): 

        # set values in xml document
        print "-------Setting Element-----------"
        for k in range(self.nac_xmlparam1_index):
            setElementValue (self.xmlDocument,self.nac_xmlparam[k],self.nac_xmlparam1[k],self.database[k].get())
            #print("self.database s"  self.database[k].get())
        
        # open XML file
        f = open ("SYSTEM.xml","w")
        #f = open (xml_path.filename,"w")

        # set xml header
        fprintf (f,'\n')
    
        # write XML document to XML file
        self.xmlDocument.writexml (f)
    
        # close XML file
        f.close ()
    
        # show confirmation message
        tkMessageBox.showerror ("Message","Configuration updated successfully")

        # exit program
        #self.quit();
Code for On Cancel
Code:
def onCancel(self): 
        # exit program
        #self.quit();
        self.pack_forget()
Attached Thumbnails
Click image for larger version

Name:	mainmenu.png
Views:	113
Size:	151.8 KB
ID:	18556   Click image for larger version

Name:	frame1_mc_config.png
Views:	96
Size:	138.1 KB
ID:	18557   Click image for larger version

Name:	Edit_xml_frame2.png
Views:	84
Size:	142.5 KB
ID:	18558   Click image for larger version

Name:	Enterxml_param_widget.png
Views:	84
Size:	163.2 KB
ID:	18559  

Last edited by srinietrx; 05-25-2015 at 07:00 AM.
 
Old 05-25-2015, 10:35 AM   #2
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
pack_forget removes the widget - whatever self represents here - from the display manager. To have it show again pack would have to be called.
 
Old 05-26-2015, 04:18 AM   #3
srinietrx
Member
 
Registered: May 2013
Posts: 101

Original Poster
Rep: Reputation: Disabled
Red face

Thanks SoftSProcket.
But I am still not able to figure out.Thats why I am sending entire python script


http://www.hastebin.com/ozerilogad.py

My problem comes when I follow these steps

1.Open Switch Installer Window(ie main menu in screenshot) click MainController button
2.Press MC_CONFIG button (frame1_mc_config screenshot).
3.By pressing XML PATH I select path and then I clicked MC SYSTEM.xml button (Edit_xml_frame2 screenshot)
4.Setting parameter press Ok or cancel
5.Now BACK To HOME button
6.When I again press MainController it goes to mc_config screenshot and then when clicked MC_CONFIG I cannot go to next frame.

I am trying to sort out this problem but in vain.

*Dont consider NACHandler class for time being.Only testing code with MainController

Last edited by srinietrx; 05-26-2015 at 04:27 AM.
 
Old 05-29-2015, 07:59 AM   #4
srinietrx
Member
 
Registered: May 2013
Posts: 101

Original Poster
Rep: Reputation: Disabled
Solved by
1.Commenting the line tk.Frame.__init__(self)
Code:
 
def nacxml(self):
    #tk.Frame.__init__(self)
    print "===Inside Nacxml1==="
2.Controller is not intialized in self.
But it is present in def __init__(self, parent, controller):
Hence added self.controller = controller in MC_CONFIG class

Code:
class MC_CONFIG(tk.Frame):
    def __init__(self, parent, controller):
       tk.Frame.__init__(self, parent)
        print "Inside MC_CONFIG"
So can be used in below method as self.controller.show_frame(StartPage)
Code:
def nacxml(self):
    tk.Frame.__init__(self)
    print "===Inside Nacxml1==="
    # xml read,edit,widget code will be added here
    self.controller.show_frame(StartPage)

Last edited by srinietrx; 05-29-2015 at 08:03 AM.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Text widget in Tkinter(Python on Win 7) not getting updated simultaneously!!! B Akshay Programming 1 02-08-2013 10:49 AM
TKinter text widget clear rockharley Linux - Newbie 4 08-15-2012 08:50 PM
basic python entry tkinter widget how-to donnied Programming 2 03-30-2008 10:36 AM
Python / Glade / GTK problem with accessing widget properties merville Programming 0 11-22-2007 08:23 PM
Python: Tkinter. Chu Programming 0 11-10-2003 01:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration