python - 有人可以向我展示一个不在循环中使用 pysimplegui 的示例 - 也许作为我可以手动更新的定义设置

标签 python progress-bar pysimplegui

我正在寻找一种使用 PYSimpleGUI 进度条的方法......没有循环 我在互联网上搜索了几天,但没有找到示例。

似乎每个人都用循环或计时器来完成他们的示例。

我想做一些更像定义的事情,我可以调用它来更新

我不知道要更改什么才能使其成为手动更新的项目... 我希望能够在脚本的开头告诉它 i=0 并定期通过脚本放置更新标记(i=i+4) 这样我就可以在脚本中的每个主要步骤完成时更新它

这是 PySimpleGUI 脚本,加上一些显示我想要执行的操作的行 当前自动迭代...并且我不知道如何更改它

我只是想学习,但在网上找不到任何示例来完成我想做的事情。

import PySimpleGUI as sg
import time
from time import sleep


import PySimpleGUI as sg

def prog():

    layout = [[sg.Text('Completed Tasks')],      
          [sg.ProgressBar(100, orientation='h', size=(50, 20), key='progressbar')],      
          [sg.Cancel()]]


    window = sg.Window('Progress').Layout(layout)      
    progress_bar = window.FindElement('progressbar')      

    for i in range(100):      
        event, values = window.Read(timeout=0)      
        progress_bar.UpdateBar(i + 4)
    time.sleep(2)
    window.Close()

prog()



time.sleep(2)
#______________________________________________________________

#I'd like to be able to do this

#i=0 at this point
prog()
#do Scripty Stuff

#Update Progress Bar Manually
#i=4 at this point

#do more scriptic writings

#Update Progress bar Manually
#i=8 at this point

#and so forth and so on until I reach 100

最佳答案

想通了

将所有内容保留为一行,而不是定义

这是一个帮助他人的例子

我刚刚在更新栏部分做了实数 但您可以使用变量 (i=0),然后在脚本中使用 i=i+1 更新它 然后在更新栏功能中使用 i 作为您的号码

i=0
progress_bar.UpdateBar(i, 5) 
#i returns a value of 0

i=i+1
progress_bar.UpdateBar(i, 5) 
#i now returns a vlaue of 1

#repeat until you reach your maximum value




#this Script will create a Progress Bar
#The Progress will be Manually Updated using the format listed below
#progress_bar.UpdateBar(Value of Bar, Maximum Bar Value)
#the Window uses a .Finalize Function to make the window Persistent

#Import the PySimpleGUI Library
import PySimpleGUI as sg
#Import the Time Library for use in this script
import time

#this is for the Layout Design of the Window
layout = [[sg.Text('Custom Text')],
              [sg.ProgressBar(1, orientation='h', size=(20, 20), key='progress')],
          ]
#This Creates the Physical Window
window = sg.Window('Window Title', layout).Finalize()
progress_bar = window.FindElement('progress')

#This Updates the Window
#progress_bar.UpdateBar(Current Value to show, Maximum Value to show)
progress_bar.UpdateBar(0, 5)
#adding time.sleep(length in Seconds) has been used to Simulate adding your script in between Bar Updates
time.sleep(.5)

progress_bar.UpdateBar(1, 5)
time.sleep(.5)

progress_bar.UpdateBar(2, 5)
time.sleep(.5)

progress_bar.UpdateBar(3, 5)
time.sleep(.5)

progress_bar.UpdateBar(4, 5)
time.sleep(.5)

progress_bar.UpdateBar(5, 5)
time.sleep(.5)
#I paused for 3 seconds at the end to give you time to see it has completed before closing the window
time.sleep(3)

#This will Close The Window
window.Close()


关于python - 有人可以向我展示一个不在循环中使用 pysimplegui 的示例 - 也许作为我可以手动更新的定义设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56516938/

相关文章:

python - 将二维数组放入 Pandas 系列

Python Selenium Firefox 驱动程序 - 禁用图像

android - AsyncTask 文件下载时 ListView 中的进度条

python - 如何在 Python 中更新 GUI 窗口?

python-3.x - 在 PySimpleGUI 的打开窗口顶部显示弹出窗口

python - 如何使用 Python matplotlib 在等高线图中绘制箭头和圆弧

python - Cython 比纯 Python 稍快或稍慢

android - 进度对话框不会显示异步任务

C# 如何获取下载文件的大小以显示进度条百分比

python - PySimpleGui - 获取按钮文本