python - Tkinter widget opens two windows -


i running tkinter 3.5 on win machine , when run code, 2 windows . expecting 1 . btw, got code form web.it working fine, except bothers me second(in backgorund) window . widget navigate trough different windows(pages) buttons .

#!/usr/bin/env python # -*- coding: utf-8 -*- #  try:     import tkinter tk  # python2 except importerror:     import tkinter tk  # python3  class wizard(tk.toplevel):     def __init__(self, npages, master=none):          self.pages = []         self.current = 0         tk.toplevel.__init__(self)          self.attributes('-topmost', true)           page in range(npages):             self.pages.append(tk.frame(self))         self.pages[0].pack(fill='both', expand=1)         self.__wizard_buttons()      def onquit(self):         pass       def __wizard_buttons(self):         indx, frm in enumerate(self.pages):             btnframe = tk.frame(frm, bd=1, bg='#3c3b37')             btnframe.pack(side='bottom', fill='x')             nextbtn = tk.button(btnframe, bd=0, bg='#f2f1f0', activebackground='#f58151', highlightcolor='red', cursor='hand2', text="siguiente >>", width=10, command=self.__next_page)             nextbtn.pack(side='right', anchor='e', padx=5, pady=5)             if indx != 0:                 prevbtn = tk.button(btnframe, bd=0, bg='#f2f1f0', activebackground='#f58151', highlightcolor='red', cursor='hand2', text="<< atras", width=10, command=self.__prev_page)                 prevbtn.pack(side='right', anchor='e', padx=5, pady=5)                 if indx == len(self.pages) - 1:                     nextbtn.configure(text="terminar", bd=0, bg='#f2f1f0', activebackground='#f58151', highlightcolor='red', cursor='hand2', command=self.close)      def __next_page(self):         if self.current == len(self.pages):             return         self.pages[self.current].pack_forget()         self.current += 1         self.pages[self.current].pack(fill='both', expand=1)      def __prev_page(self):         if self.current == 0:             return         self.pages[self.current].pack_forget()         self.current -= 1         self.pages[self.current].pack(fill='both', expand=1)      def add_page_body(self, body):         body.pack(side='top', fill='both', padx=6, pady=12)      def page(self, page_num):         try:             page = self.pages[page_num]         except keyerror("pagina invalida! : %s" % page_num):             return 0         return page      def close(self):         if self.validate():             self.master.iconify()             print (' tk wizard finished... ')             self.destroy()             self.master.destroy()      def validate(self):         return 1   if __name__ == "__main__":     root = tk.tk()     root.title(' tk wizards ')     wizard = wizard(npages=3, master=root)     wizard.minsize(400, 350)     page0 = tk.label(wizard.page(0), text='pagina 1: ...bienvenido al wizard de tk !')     page1 = tk.label(wizard.page(1), text='pagina 2: acepta las condiciones de la wtfpl ?')     page2 = tk.label(wizard.page(2), text='pagina 3: felicitaciones, nada no se ha instalado correctamente.')     wizard.add_page_body(page0)     wizard.add_page_body(page1)     wizard.add_page_body(page2)     root.mainloop() 

the additional, blank window root window. add call

root.withdraw() 

just underneath root.title(' tk wizards ') line, should trick


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -