Hi All,
I am in the process of learning python. I have a gui that gives the user the option of selecting between two applications to run. Currently each button calls one of these two modules (another python script), using the import command. Since it takes a few minutes for the next gui to pop up, I would like the Status bar at the bottom to say -"Thinking", or to have an oscillating bar.
My problem is that when I push the button, only the first of the two actions is implemented and the second is ignored. Specifically, the text changes but the gui_cc.py module does not get called. I need for them both to occur at the same time. I have attached my code as I am sure my description is confusing. The lines that are commented out are those that change the text. The code works with these lines commented out.
Thanks in advance for your help!
Alexis

from Tkinter import *
import re,os

class Application:
    #Main GUI application
    def __init__(self):
        self.root = Tk()
        self.mainWindow=Frame(self.root,borderwidth=2,relief=RIDGE)
        self.mainWindow.pack()
        self.font=Font(family="Helvetica", size="12")
        self.chooser()
        self.root.mainloop()
    def chooser(self):
        self.start=Label(self.mainWindow,text="Change % Canopy Cover for:",bd=6,font=Font(family="Helvitica",size="14",weight="bold"))
        self.start.grid(column=0,row=0,ipadx=0,padx=0,pady=0,sticky=W)
        self.lc_class = Button(self.mainWindow, text ="Each Land Cover Type",command=self.indiv,bd=4,font=Font(family="Helvitica",size="10",weight="bold"))
        self.lc_class.grid(column=0,row=1,ipadx=8,padx=2,pady=2,sticky=EW)
        self.area = Button(self.mainWindow, text ="Entire Region",command=self.all,bd=4,font=Font(family="Helvitica",size="10",weight="bold"))
        self.area.grid(column=0,row=3,ipadx=10,padx=2,pady=2,sticky=EW)
        self.exit_button=Button(self.mainWindow,text="Cancel",command=self.exit,bg="red",bd=4,font=Font(family="Helvitica",size="10",weight="bold"))
        self.exit_button.grid(column=0,row=4,ipadx=5,padx=3,pady=3,sticky=SE)
        self.status = Label(None, text="Status:",bd=1, relief=SUNKEN, anchor=W)
        self.status.pack(side=BOTTOM, fill=X)
    def indiv(self):  
        #self.status.config(text="Status: THINKING...", bd=1, relief=SUNKEN, anchor=S,font=Font(family="Helvitica",size="14",weight="bold"))
        #return
        import gui_cc
    def all(self):
        import gui_cc_all
    def exit(self):
        self.root.destroy()

a = Application()

Recommended Answers

All 7 Replies

Hi Alexis

Why did you use a return statement at line 26 ?
Basically a return statement in a function tells it to ... return :) ie exit at this point. So any code beyond that point won't be executed.

thats a comment, anything after a hash is a comment in python

I was about to try and help, but then I realised this is Tk. :(

thats a comment, anything after a hash is a comment in python

Yeah a hash is a comment. The OP commented the code that is creating the problem.
The issue isn't comments but why the function doesn't execute both commands.
I think the return statement is the issue.

When I remove the 'return' statement, 'self.status.config' (to change the text) is skipped and the import starts. When I add the return statement, the text changes but no import. I am trying to thread the statements, but once again only the import works...
I am at a loss for the time being...

Thanks for all the suggestions/help thus far!
Alexis

have you had a look at Threading?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.