I'm new to python, I'm trying to write a small program that will update find files and update then in directory ( this is working )
The problem I'm facing is that I can not get two functions to run at the same time. For example While the code searches for the file and replaces them, also display a small popup window showing an text message that the system is busy. and after the code has completed show a popup message Completed.
!/usr/bin/python
# -*- coding: utf-8 -*-
#Shell script version 2
import os
import shutil
from Tkinter import *
import tkMessageBox
import tkSimpleDialog
from threading import Thread
import threading
import time
from multiprocessing import Process
import sys
from tkinter.ttk import *
import multiprocessing
Search = 'c:\\'
search_folder = ''
class popupWindow(object):
def __init__(self,parent):
top=self.top=Toplevel(parent)
self.l=Label(top,text="Patch is running")
self.l.pack()
self.b=Button(top,text='Ok',command=self.cleanup)
self.b.pack()
def cleanup(self):
#self.value=self.e.get()
self.top.destroy()
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
photo = PhotoImage(file="C:\\IMAGE.gif")
self.parent.title("Off Line Playe Patch")
self.style = Style()
self.style.theme_use("default")
self.pack(fill=BOTH, expand=1)
W = Label(self,image=photo)
W.photo = photo
W.pack()
#Button(tk,text='foo',command=bar).pack()
quitButton = Button(self, text="Apply Patch",command=self.StPatch)
quitButton.place(x=80, y=0)
def StPatch(self):
# Replaces shell.htm with correct file
def FoundShell():
for root, dirs, files in os.walk(search_folder):
for file in files:
print os.path.join(root,file)
if file == 'shell.htm':
print "found file"
Shell = os.path.join(root,file)
os.remove(Shell)
shutil.copy2('./shell.htm',Shell)
def Hello():
self.w = popupWindow(self.parent)
self.parent.wait_window(self.w.top)
i = 0
while i < 100000:
print('hello world')
i=i+1
if os.path.exists('C:\Player - Office 2010'):
print 'Found Folder'
search_folder = 'C:\Player - Office 2010'
tkMessageBox.showinfo("Update Done", "Update has been applyed successfuly ", command=FoundShell())
else: # request user to enter path to Directory
print 'not found'
search_folder = tkSimpleDialog.askstring('Path', 'Please enter Path to Offline Player', )
print search_folder
tkMessageBox.showinfo("Update Done", "Update has been applyed successfuly ", command=FoundShell())
#t1 = threading.Thread(target=RunScript(self))
#t1.start()
#t1.join()
#Hello()
# the join means wait untill it finished
root = Tk()
app = Example(root)
root.mainloop()
import thread
from template import *
from graph import *
try:
thread.start_new_thread(main,())
thread.start_new_thread(graph,())
except KeyboardInterrupt:
thread.exit()
while 1:
pass
This is an example of how to call 2 functions at a time using multiThreads. Calling Function main
with no params "()
" from Template file module, and graph
function with no params "()
" from module graph.
And use this in an auxiliary file called run.py
The while 1
keep the thread running. until KeyboardInterrupt
is handled.
Wish this could help!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments