0

+ +_+ + +_+ + +_+ + +_+ + +_+ + +_+ ++

** 没关系!** 这个问题已经回答了!它只需要在底部而不是根蜂蜡...

对。这是底部。它只需要一点代码清理:)....没关系。不管怎么说,还是要谢谢你!

#omit root
app = App()
app.mainloop()

+ +_+ + +_+ + +_+ + +_+ + +_+ + +_+ + ++

我已经努力了两个小时来摆脱第二个窗口。在我实现了询问文件夹名称的弹出窗口后,程序运行时我突然打开了两个窗口。我只想要一个,真的很烦人。我希望这个程序用四个按钮打开一个窗口,并在它们上方有一个标题。其中一个按钮要求输入,然后它就消失了。有人可以帮我回到一个窗口吗?谢谢你。我为凌乱的代码道歉,这是我第一个这种风格的脚本。

#!/usr/bin/python
            #from Tkinter import *
            import Tkinter as tk

            import os
            import tkFileDialog

            class App(tk.Tk):
            #class App:

                #def __init__(self, master):
                def __init__(self):
                tk.Tk.__init__(self)


                frame = tk.Frame(self)
                frame.pack()

                self.button = tk.Button(frame, text="leave", fg="red", command=frame.quit)
                self.button.pack(side=tk.LEFT)

                self.fetch = tk.Button(frame,text="Choose Folder for Pictures",fg="salmon",command=self.choose)
                self.fetch.pack(side=tk.LEFT)

                self.fetch = tk.Button(frame,text="Name folder on site (public)",command=self.on_click)
                self.fetch.pack(side=tk.LEFT)

                self.hi_there = tk.Button(frame, text="Create code for images", fg="brown", command=self.generate)
                self.hi_there.pack(side=tk.LEFT)
                #oroville dam is the highest in the country
                w = tk.Label(text="MSP Art File Fetcher")
                w.pack()
             # Toplevel window

                top = self.top = tk.Toplevel(self)
                myLabel = tk.Label(top, text='Name of image directory:')
                myLabel.pack()

                self.myEntryBox = tk.Entry(top)
                self.myEntryBox.pack()

                mySubmitButton = tk.Button(top, text='Done', command=self.submit_name)
                mySubmitButton.pack()

                top.protocol("WM_DELETE_WINDOW", self.save_top)

                top.withdraw()



                def save_top(self):
                self.top.withdraw()


                def choose(self):
                self.foldername=tkFileDialog.askdirectory()
                print self.foldername


                def name(self):
                print self.foldername

                def generate(self): 
                print self.foldername  
                    self.path=self.foldername  # failing, works
                self.dirlist=os.listdir(self.path)
                yoz = file('demcode.txt','wt')#totally works
                f=open('demcode.txt', 'r+')
                f.write(self.foldername)
                f.write('\ndo not be a crack addic\n')
                f.write('\n')
                print self.dirlist
                print self.dirlist[0]
                self.y=len(self.dirlist)
                print self.y
                for x in range(0,self.y): #works great
                #for x in range(0,4):#self.y: #failing
                    print 'We\'re on image %d' % (x)
                #print in self.dirlist
                f.write('\n'.join(self.dirlist[0]))#returns a vertical word!?
                f.write('\n')   
                f.write(self.dirlist[0])
                f.write('\n')
                f.write('\n')
                f.write('\n')   
                f.write(', '.join(self.dirlist))#CAUTION, will write over existing data

                def say_hi(self):
                print "don't be a crack addic"

                def submit_name(self):
                if self.myEntryBox.get() != "":
                    self.username = self.myEntryBox.get()
                    self.myEntryBox.delete(0, 'end')
                    self.top.withdraw()

                def on_click(self):
                self.top.deiconify()
            """
                def show_name(self):
                self.mainText.delete('1.0', 'end')
                self.mainText.insert('end', 'Welcome ' + self.username + '!')
            """
            root = tk.Tk()

            app = App()

            root.mainloop()
            """
            """
            achieve this format of html.  python program will loop every file in the directory, placing the name of the file in the set path (asked directory name), and write the approiate code for lightbox
            """
            <h1>MSP (Acorns) Gallery</h1>
            #http://www.mspart.com/lightbox.html
            <div id="page">
            <div id="images">
            <ul class="gallery">
              <a href="images/Pastels/alpha_farm.jpg" rel="lightbox"> </a>
              <li><a href="images/Pastels/alpha_farm.jpg" rel="lightbox"><img src="images/Pastels/alpha_farm.jpg" alt="description"></a></li>
              <a href="images/Pastels/_day_island.jpg" rel="lightbox"> </a>
              <li><a href="images/Pastels/_day_island.jpg" rel="lightbox"><img src="images/Pastels/_day_island.jpg" alt="description"></a>
            </li></ul>
            </div>
            </div>
4

1 回答 1

0

在您的app班级中,您已经定义了一个Tk. 因此,当您定义 anapp和 another时Tk,您正在创建两个窗口。删除一个或另一个应该只创建一个窗口。

于 2016-08-26T15:08:18.160 回答