Tkinter:顶级窗口未显示

编程入门 行业动态 更新时间:2024-10-21 11:41:14
本文介绍了Tkinter:顶级窗口未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我试图通过单击顶层窗口的按钮来复制 ftp 服务器上的文件.我希望当前的顶级窗口消失,并出现一个新的窗口,在该窗口上显示正在复制的文件的名称.复制完成后,窗口应该销毁.但是除非我使用pdb"或出现错误/弹出窗口,否则不会出现新窗口.这是调试所需的代码.(原谅我没有使用类)

I am trying to copy files on a ftp server via a button click of a toplevel window. I want the current toplevel window to disappear and a new one to appear on which the name of the file being copied is dispalyed. After the copying is completed, the window should destroy. But the new window does not appear unless I use "pdb" or an error/pop up occurs. Here's the required code for debugging. (Excuse me for not using Classes)

copy_window=Toplevel(main_window)
copy_window.resizable(False,False)
main_window.withdraw()
copy_window_Label1=Label(copy_window,text="\nTick the files you want to copy.\n").pack()

File_frame=Frame(copy_window)
Frame1=Frame(File_frame)
Frame2=Frame(File_frame)

#Some file and folder name setting code for each file edited
x_Checkbutton=Checkbutton(Frame1,variable=x_Check,text=x_file_name+" will be copied in ").pack(side=LEFT)
x_Entry=Entry(Frame1,width=10)
x_Entry.insert(0,folder_1)
x_Entry.pack(side=LEFT)
y_Checkbutton=Checkbutton(Frame1,variable=y_Check,text=y_file_name+" will be copied in ").pack(side=LEFT)
y_Entry=Entry(Frame2,width=10)



def ok_button_click():
    if (x_check.get()==1 or y_check.get()==1):

        progress_window=Toplevel(copy_window)
        label=StringVar()
        p_label=Label(progress_window,textvariable=label).pack()
        label.set("\nPlease wait while the files are being copied..\n")
        copy_window.withdraw()

        site=FTP("12345")           
        site.login("a","a")             

        x_result=True
        y_result=True

        if x_check.get()==1:                
            site.cwd(sub_path)
            if ((x_Entry.get() in site.nlst())==False):
                site.mkd(x_Entry.get())
            else:
                site.cwd(x_Entry.get())
                for item in site.nlst():
                    if (item.startswith('x_'+name):
                        x_result=tkMessageBox.askyesno("Warning !",item+" is already present in "+x_Entry.get()+"\nDo you want to copy this new file?\nIf you select Yes, Previous file will be deleted")
                        if x_result==True:
                            site.delete(item)
                        break
                site.cwd(sub_path)      
            if x_result==True:
                label.set("\nPlease wait, while the x file is being copied..\n")
                site.cwd(x_Entry.get())
                with open(x_file_name,"rb") as f:
                    site.storfile("STOR "+x_file_name,f)
        if y_check.get()==1:
            site.cwd(sub_path)
            if ((y_Entry.get() in site.nlst())==False):
                site.mkd(y_Entry.get())
            else:
                site.cwd(y_Entry.get())
                for item in site.nlst():
                    if item.startswith('y_'):
                        y_result=tkMessageBox.askyesno("Warning !",item+" is already present in "+y_Entry.get()+"\nDo you want to copy this new file?\nIf you select Yes, Previous file will be deleted")
                        if y_result==True:
                            site.delete(item)
                        break
                site.cwd(sub_path)      
            if y_result==True:
                label.set("\nPlease wait, while the y file is being copied..\n")
                site.cwd(y_Entry.get())
                with open(y_file_name,"rb") as f:
                    site.storfile("STOR "+y_file_name,f)            

        progress_window.destroy()
        if not (y_result==False and x_result==False):
            tkMessageBox.showinfo("Success !","Files copied successfully.")
    copy_window.destroy()
    main_window.update()
    main_window.deiconify()

ok_button=Button(copy_window,text="OK",width="10",command=ok_button_click).pack()

推荐答案

如果 x_result==True:label.set("\n请稍候,正在复制 x 文件..\n")progress_window.update()

if x_result==True: label.set("\nPlease wait, while the x file isbeing copied..\n") progress_window.update()

我每次更改标签值时都添加了progress_window.update().对我有用.

I just added progress_window.update(), each time I changed the label value. Works for me.

如果 y_result==True:label.set("\n请稍候,正在复制 y 文件..\n")progress_window.update()

if y_result==True: label.set("\nPlease wait, while the y file isbeing copied..\n") progress_window.update()

这篇关于Tkinter:顶级窗口未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 07:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390627.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   Tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!