1,105,375 Community Members

newbie custom Dialog Window in Tkinter

Member Avatar
Gustavo_B
Newbie Poster
1 post since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I'm writing a small application that gets some data from the user and launches a second application related to what process the user is working on. So, sometimes the user needs to choose from different versions of the same aplication. I decided that after the Ok button is pressed in main window, the application searches in some folders and open a second window with the different versions avaliable to that application. My problem is that when I launch the second window with the options my main application continues to run with default options. I press the buttons in the second window and nothing happens.
versionDialog is the class that is called to raise the second window.

thanks for helping

class versionDialog : 
    def escolha (self, item) :
        self.versao = item
        print item
        self.wdw.destroy

    def __init__ (self, message, options) :
        self.wdw = Toplevel()
        self.wdw.transient()
        Label(self.wdw , text= message).pack()
        for item in options :
            Button(self.wdw, text= item, command= self.escolha(item)).pack()

.
.
.
.
.

Dialog = versionDialog("Carregar script em qual versão?", listVersions)
app.version = Dialog.versao
app.launch()
Member Avatar
pyguy62
Posting Whiz
346 posts since Aug 2011
Reputation Points: 23 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
0
 

your command for that button is going to cause issues, I've noticed whenever you have command=method_or_function(parameter) it immediately attempts to run that command, I've side stepped this by creating methods that know to grab that parameter.I'm not completely sure about the rest of the issue, I'd need to see more of the code. Here's an example of what I was talking about though:

self.searchlbl=Label(self,text='Search:')
        self.searchlbl.grid(row=2,column=0)
        self.search=ttk.Combobox(self)
        self.search['values']=contact_list
        self.search.bind('<Return>',self.eventsearch_for)
        self.search.focus_set()
        self.submit=ttk.Button(self,text='Search',command=self.search_for)
        self.submit.bind('<Return>',self.eventsearch_for)
        self.submit.grid(row=2,column=5)
    
      def search_for(self):
         self.search1=self.search.get()
         self.search.delete(0,END)
         query_key=self.search1.title()
         if query_key in ab.keys():
            pop_up(query_key)
         else:
            fail('dict',query_key)
Member Avatar
woooee
Posting Maven
2,793 posts since Dec 2006
Reputation Points: 783 [?]
Q&As Helped to Solve: 836 [?]
Skill Endorsements: 12 [?]
 
0
 

Pyguy62 is correct about the button call back. To send arguments to a function from a Tkinter callback you use partial.

from functools import partial
for item in options :
    Button(self.wdw, text= item, command= parital(self.escolha, item=item)).pack()

My problem is that when I launch the second window with the options my main application continues to run with default options

How are you accessing/passing the values from the second window to the first window's program?

Also you probably want to include "takefocus=True" when creating the Toplevel GUI.

Member Avatar
pyguy62
Posting Whiz
346 posts since Aug 2011
Reputation Points: 23 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
0
 

Oh I hadn't used the partial tool yet, so it presets the arg without immediately running it?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: