本文整理匯總了Python中ttk.Progressbar.update_idletasks方法的典型用法代碼示例。如果您正苦於以下問題:Python Progressbar.update_idletasks方法的具體用法?Python Progressbar.update_idletasks怎麽用?Python Progressbar.update_idletasks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ttk.Progressbar
的用法示例。
在下文中一共展示了Progressbar.update_idletasks方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FindServer
# 需要導入模塊: from ttk import Progressbar [as 別名]
# 或者: from ttk.Progressbar import update_idletasks [as 別名]
class FindServer(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.selected = "";
self.controller = controller
label = Label(self, text="Select server", font=TITLE_FONT, justify=CENTER, anchor=CENTER)
label.pack(side="top", fill="x", pady=10)
self.button1 = Button(self, text="Next",state="disabled", command=self.callback_choose)
button2 = Button(self, text="Refresh", command=self.callback_refresh)
button3 = Button(self, text="Back", command=self.callback_start)
scrollbar = Scrollbar(self)
self.mylist = Listbox(self, width=100, yscrollcommand = scrollbar.set )
self.mylist.bind("<Double-Button-1>", self.twoClick)
self.button1.pack()
button2.pack()
button3.pack()
# create list with a scroolbar
scrollbar.pack( side = "right", fill="y" )
self.mylist.pack( side = "top", fill = "x", ipadx=20, ipady=20, padx=20, pady=20 )
scrollbar.config( command = self.mylist.yview )
# create a progress bar
label2 = Label(self, text="Refresh progress bar", justify='center', anchor='center')
label2.pack(side="top", fill="x")
self.bar_lenght = 200
self.pb = Progressbar(self, length=self.bar_lenght, mode='determinate')
self.pb.pack(side="top", anchor='center', ipadx=20, ipady=20, padx=10, pady=10)
self.pb.config(value=0)
# to select he server user must double-click on it
def twoClick(self, event):
widget = event.widget
selection=widget.curselection()
value = widget.get(selection[0])
self.selected = value
self.button1.config(state="normal")
# save the selected server in a global variable
SELECTED_SERV = SERVER_LIST[selection[0]]
set_globvar(SELECTED_SERV)
# listen for broadcasts from port 8192
def listen_broadcasts(self, port, timeout):
# Set the progress bar to 0
self.pb.config(value=0)
step_size = ((self.bar_lenght/(MAX_NR_OF_SERVERS+1))/2)
list_of_servers = []
# Initialize the listener
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind(('', port))
s.settimeout(LISTENING_TIMEOUT)
# Listen for a number of times to get multiple servers
for _ in range(MAX_NR_OF_SERVERS + 1):
# Update the progress bar
self.pb.step(step_size)
self.pb.update_idletasks()
try:
message, address = s.recvfrom(8192)
m_split = message.split(';')
if m_split[0] == '\HELLO':
server_id = (m_split[1], address)
# Check if the server has not yet broadcasted itself.
if server_id not in list_of_servers:
list_of_servers.append(server_id)
except:
pass
# Close the socket
s.close()
if not list_of_servers:
# If no server found, pop a warning message.
tkMessageBox.showwarning("Find Servers", "No servers found. Refresh or create a new game.")
# Set the progress bar back to 0
self.pb.config(value=0)
# Return the whole list of available servers
return list_of_servers
# service the refresh button
def callback_refresh(self):
global SERVER_LIST
self.mylist.delete(0,END)
SERVER_LIST = self.listen_broadcasts(BROADCASTING_PORT, LISTENING_TIMEOUT)
for server_el in SERVER_LIST:
self.mylist.insert(END,(" "+str(server_el[0])+" IP: "+str(server_el[1])+" Time: "+str(time.asctime())))
def callback_choose(self):
self.mylist.delete(0,END)
self.button1.config(state="disabled")
self.controller.show_frame("ChooseType")
def callback_start(self):
self.mylist.delete(0,END)
self.button1.config(state="disabled")
self.controller.show_frame("StartPage")