Answer the question
In order to leave comments, you need to log in
Python. How to implement program reuse without restart?
Hello, I wrote this code:
# -*- coding: utf-8 -*-
from Tkinter import *
import urllib, ttk, tkMessageBox
from threading import Thread
from Queue import Queue
queue = Queue()
def func():
arc1 = c1.get()
arc2 = c2.get()
def downloader(url,file):
urllib.urlretrieve(url, file)
queue.put(True)
if arc1 == 1:
downloader('http://cs1632v4.vk.me/u222124/audios/88970df3fe1f.mp3','file1.mp3')
if arc2 == 1:
downloader('http://cs536301v4.vk.me/u131194151/audios/bc2867aeb217.mp3','file2.mp3')
th = Thread(target=func, args=())
def starter(event):
th.start()
pb.pack()
pb.start()
root = Tk()
def task():
try:
q = queue.get_nowait()
except:
q = False
if q:
tkMessageBox.showinfo('Done')
root.after(1000, task)
root.after(1000, task)
c1 = IntVar()
c2 = IntVar()
chk1 = Checkbutton(root, text = '1', onvalue = 1, offvalue = 0, variable = c1)
chk2 = Checkbutton(root, text = '2', onvalue = 1, offvalue = 0, variable = c2)
pb = ttk.Progressbar(length=200, orient='horizontal', mode='indeterminate')
but = Button(root, text = 'Go!')
root.minsize(width=400, height=350)
but.bind('<Button-1>', starter)
but.pack()
chk1.pack()
chk2.pack()
root.mainloop()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question