我正在尝试创建一个状态/进度条,显示剩余的网页数量。我迷失在如何传递模块之间的页面数量上。我想通过调用tkinter窗口类我犯了一个错误。任何关于如何调用此模块并传递pg / pages变量的帮助将不胜感激。
获取页数的模块:
from ProgressBar import StatusWindow
pages = 25
class crawler:
def get_pagecount():
for eachPage in range(1,pages):
pg = eachPage
Complete = '{:.0%}'.format(pg/pages)
print(Complete)
StatusWindow(pages,pg) """<== How do I call the progress bar and pass these variables?"""
if __name__=='__main__':
crawler.get_pagecount()
进度:
from tkinter import *
from tkinter import ttk
backRGB = '#e5e5e5'
root = Tk()
root.configure(bg=backRGB)
root.configure()
class StatusWindow(Frame,ToDo,Done): """<==Probably not where I should be calling and passing variables?"""
def __init__(self,master = None):
Frame.__init__(self,master)
self.master = master
self.init_window()
self.grid()
self.tk_setPalette(background='#e5e5e5', foreground = '#001030',activeBackground='#001030',activeForeground='white')
ToDo = 10
Done = 5
self.Progress_Bar(ToDo,Done)
def Progress_Bar(self,ToDo,Done):
progressbar = ttk.Progressbar(root, orient = HORIZONTAL, length = 300)
progressbar.grid(row=9, column = 0)
progressbar.config(mode = 'determinate', maximum = ToDo, value = Done)
def init_window(self):
self.master.title("Program Status")
self.pack(fill=BOTH, expand=1)
menu = Menu(self.master)
self.master.config(menu=menu)
text = Text(self.master)
app = StatusWindow(root)
root.mainloop()