File Browse and Button Customzied #255
lifeofpi2012
started this conversation in
Feature request
Replies: 1 comment 1 reply
-
受限于浏览器的安全策略,是无法通过浏览器扫描用户本地的文件的。不过倒是可以通过python的文件浏览api来访问文件,这里有个示例应用: import os
from functools import partial
from pywebio import start_server
from pywebio.output import *
from pywebio.session import *
from pywebio.input import *
@use_scope('files', clear=True)
def show_files(path):
path = os.path.normpath(path)
files = os.listdir(path)
files = [f + '/' if os.path.isdir(os.path.join(path, f)) else f for f in files]
files.sort(key=lambda f: not f.endswith('/'))
files.insert(0, '../')
put_markdown('Path: `%s`' % path)
put_table([
[f, put_buttons(['Open'], onclick=[partial(show_files, os.path.join(path, f))]) if f.endswith('/') else '']
for f in files
], header="Name Actions".split())
tdata = []
for f in files:
if f.endswith('/'):
full_path = os.path.join(path, f)
tdata.append([f, put_buttons(['Open'], onclick=[partial(show_files, full_path)])])
else:
tdata.append([f, ''])
put_table(tdata, header=["Name", "Actions"])
def main():
show_files(input("Input a path of your computer:"))
hold()
if __name__ == '__main__':
start_server(main, port=8080) 对控件进行自定义样式,可以使用 style() 方法 或者使用 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Weimin
请教两个问题
之前用PysimpleGui时,可以使用FileBrowse或者FolderBrowse这种API获取本地文件的path,如下图
pywebio的doc里面,好像只能找到file_upload这种方式,必须要通过"文件上传"的方式?
2.客制化Button
之前用PyQt5写local tool时,可以对button做克制化,利用QSS(类CSS)将部件外观客制化,类似下面这样
请教一下,在pywebio中,通过put_button或者put_buttons时,如果要对button做克制化,请问有什么途径么?
Thanks a lot
Beta Was this translation helpful? Give feedback.
All reactions