python中的两个窗口,吓坏了我

python中的两个窗口,吓坏了我,python,windows,tkinter,Python,Windows,Tkinter,++_+++_+++_+++_+++_+++_+++ **没关系!**这个问题已经回答了!它只需要在底部放这个而不是根蜂蜡 是的。那是底部。它只需要一点代码清理:)。。。。不要介意。无论如何谢谢你 #omit root app = App() app.mainloop() ++_+++_+++_+++_+++_+++_++++ 我花了两个小时努力摆脱第二扇窗户。在我实现了请求文件夹名称的弹出窗口之后,当程序运行时,我突然打开了两个窗口。我只想要一个,这真的很让人恼火。我希望这个程序打开一个有四

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

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

是的。那是底部。它只需要一点代码清理:)。。。。不要介意。无论如何谢谢你

#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>
#/usr/bin/python
#从Tkinter进口*
将Tkinter作为tk导入
导入操作系统
导入tkFileDialog
类应用程序(tk.tk):
#类应用程序:
#定义初始(自我,主):
定义初始化(自):
tk.tk.\uuuuu初始化(self)
框架=传统框架(自身)
frame.pack()
self.button=tk.button(frame,text=“leave”,fg=“red”,command=frame.quit)
自动按钮包(侧=左侧)
self.fetch=tk.Button(frame,text=“为图片选择文件夹”,fg=“鲑鱼”,command=self.Choose)
self.fetch.pack(side=tk.LEFT)
self.fetch=tk.Button(frame,text=“站点上的名称文件夹(公共)”,command=self.on_单击)
self.fetch.pack(side=tk.LEFT)
self.hi_there=tk.Button(frame,text=“为图像创建代码”,fg=“brown”,command=self.generate)
self.hi_there.pack(侧面=左侧)
#奥罗维尔大坝是全国最高的
w=tk.Label(text=“MSP艺术文件获取程序”)
w、 包()
#顶层窗口
top=self.top=tk.Toplevel(self)
myLabel=tk.Label(顶部,text='image目录的名称:')
myLabel.pack()
self.myEntryBox=tk.Entry(顶部)
self.myEntryBox.pack()
mySubmitButton=tk.Button(顶部,text='Done',command=self.submit\u name)
mySubmitButton.pack()
协议(“WM_删除_窗口”,self.save_top)
撤回
def保存_顶部(自身):
self.top.draw()
def选择(自我):
self.foldername=tkFileDialog.askdirectory()
打印self.foldername
def名称(自我):
打印self.foldername
def生成(自身):
打印self.foldername
self.path=self.foldername#失败,有效
self.dirlist=os.listdir(self.path)
yoz=file('demcode.txt','wt')#完全可以工作
f=open('demcode.txt','r+'))
f、 写入(self.foldername)
f、 写入('\n不是裂纹添加项\n')
f、 写入('\n')
打印自我目录列表
打印self.dirlist[0]
self.y=len(self.dirlist)
打印self.y
对于范围内的x(0,self.y):#效果很好
#对于范围(0,4)内的x:#self.y:#失败
打印“我们在图像%d上”(x)
#在self.dirlist中打印
f、 write('\n.join(self.dirlist[0])#返回垂直单词!?
f、 写入('\n')
f、 写入(self.dirlist[0])
f、 写入('\n')
f、 写入('\n')
f、 写入('\n')
f、 写入(“,”.join(self.dirlist))#注意,将写入现有数据
def say_hi(self):
打印“不要成为一个疯子”
def提交名称(自我):
如果self.myEntryBox.get()!="":
self.username=self.myEntryBox.get()
self.myEntryBox.delete(0,“结束”)
self.top.draw()
单击时的def(自身):
self.top.deiconify()
"""
def显示_名称(自身):
self.mainText.delete('1.0','end')
self.mainText.insert('end','Welcome'+self.username+'!'))
"""
root=tk.tk()
app=app()
root.mainloop()
"""
"""
实现这种格式的html。python程序将循环目录中的每个文件,将文件名放在设置的路径(询问的目录名)中,并为lightbox编写相应的代码
"""
MSP(橡子)画廊
#http://www.mspart.com/lightbox.html

在你的
应用程序
类中,你已经定义了一个
Tk
。因此,当你定义一个
应用程序
和另一个
Tk
时,你正在创建两个窗口。删除其中一个或另一个应该只创建一个窗口。

如果你找到了解决方案,你应该将其作为答案发布。是的,我刚刚创建了我的个人资料。有一个奇怪的八个小时的溢出阻止我添加答案或将其标记为已解决。。。