sg.ColorChooserButton()
将16进制颜色码(hex)赋值给目标元素
ColorChooserButton(
button_text,
# 按钮元素要显示的文本
target=key,
# 显示颜色码的目标元素的key,)
------------------------
image_filename=None,
image_data=None,
image_size=(None, None),
image_subsample=None,
tooltip=None,
border_width=None,
size=(None, None),
auto_size_button=None,
button_color=None,(按钮文本颜色,按钮北京颜色)
disabled=False,
font=None,(字体,大小)
bind_return_key=False,
# 绑定回车键
# 按一下回车键,调出颜色选择界面。
focus=False,
pad=None,
key=None,
)
import PySimpleGUI as sg
layout = [[sg.ColorChooserButton("颜色选择按钮",target='-In-',key='-ccb-',bind_return_key=True)],
[sg.In(key='-In-',enable_events=True)]]
window = sg.Window("pthon GUI", layout, keep_on_top=True, resizable=True)
result = True
while True:
event, value = window.read()
print(event)
if event==None:
break
if event == "-In-":
window['-ccb-'].update(button_color=('white',value['-In-']))
window.close()
sg.FileBrowse()
点击按钮选择文件后,可以获得文件的绝对路径。
FileBrowse(
button_text="Browse",
# 按钮元素上要显示的文本
target=key,
# 显示路径的目标元素的key 路径默认写入其左边输入框后面几个都是一样(FileBrowse,FilesBrowse,FileSaveAs,FolderBrowse
file_types=(('ALL Files', '*.*'),),
# 只显示指定的文件类型 '*.pdf'
# 只显示指定的文件名称 'text.*'
initial_folder=None,
# 默认路径设定
-----------------------------
tooltip=None,
size=(None, None),
auto_size_button=None,
button_color=None,
enable_events=False,
font=None,
disabled=False,
pad=None,
key=None,
)
单个文件选择时用FileBrowse,多个文件选择时用FilesBrowse
import PySimpleGUI as sg
layout = [[sg.FileBrowse('单文本选择',target='-In-',
# file_types=(('All Files','*.*')),
# file_types=(('All Files','*.*'),) ,#括号中间的逗号不能省略
# file_types=(('All Files','*.png'),('All Files','*.py'),) ,#括号中间的逗号不能省略
# file_types=(('png/txt','*.png'),('png/txt','*.py'),), #括号中间的逗号不能省略
file_types=(('png/txt','2.png'),('png/txt','*.py'),), #括号中间的逗号不能省略
initial_folder=r'C:\Users\Admin\Desktop'
),
sg.FilesBrowse('多文本选择',target='-In-',
# file_types=(('All Files','*.*')),
# file_types=(('All Files','*.*'),) ,#括号中间的逗号不能省略
# file_types=(('All Files','*.png'),('All Files','*.py'),) ,#括号中间的逗号不能省略
# file_types=(('png/txt','*.png'),('png/txt','*.py'),), #括号中间的逗号不能省略
file_types=(('png/txt','*.png'),('png/txt','*.py'),), #括号中间的逗号不能省略
initial_folder=r'C:\Users\Admin\Desktop'
)
],[sg.In(key='-In-')]]
window = sg.Window("pthon GUI", layout, keep_on_top=True, resizable=True)
result = True
while True:
event, value = window.read()
print(event)
if event==None:
break
if event == "-In-":
window['-ccb-'].update(button_color=('white',value['-In-']))
window.close()
sg.FileSaveAs()
注意: 文件名重复时系统会提醒文件名重复。
FileSaveAs(
button_text="Save As...",
target=key,
file_types=(('ALL Files', '*.*'),),
initial_folder=None,
disabled=False,
tooltip=None,
size=(None, None),
auto_size_button=None,
button_color=None,
enable_events=False,
font=None,
pad=None,
key=None,
)
sg.FolderBrowse()
FolderBrowse(
button_text="Browse",
target=key,
initial_folder=None,
tooltip=None,
size=(None, None),
auto_size_button=None,
button_color=None,
disabled=False,
enable_events=False,
font=None,
pad=None,
key=None,
)
如果不设定target,
路径默认显示到为选择器同行且左边的第一个输入框。
[[sg.In(),sg.FileSaveAs()]]
左边没有输入框,默认显示到最右边的单行显示/输入框里。
[[sg.FileSaveAs(),sg.In(),sg.In(),]]
总结
layout=[[sg.In(),sg.FolderBrowse()]]
layout=[[sg.In(),sg.FileSaveAs()]]
layout=[[sg.In(),sg.FileBrowse()]]
layout=[[sg.In(),sg.FilesBrowse()]]
layout=[[sg.In(key='1'),sg.ColorChooserButton(button_text='select',target='1')]]
sg.CalendarButton()
CalendarButton(
button_text,
# 按钮上显示的文本
target=(key),
# 选择的日期要显示的位置
close_when_date_chosen=True,
# 选择日期后 日历界面关闭
default_date_m_d_y=(None, None, None),
# 默认值设定
locale=None, #时区设置,北京时间,德国(de-DE),西班牙(es)时间等
format="%Y-%m-%d %H:%M:%S",
begin_at_sunday_plus=0,
month_names=None,
day_abbreviations=None,
title="Choose Date",
no_titlebar=True,
location=(None, None),
-------------------------------------
image_filename=None,
image_data=None,
image_size=(None, None),
image_subsample=None,
tooltip=None,
border_width=None,
size=(None, None),
auto_size_button=None,
button_color=None,
disabled=False,
font=None,
bind_return_key=False,
focus=False,
pad=None,
enable_events=None,
key=None,
)
import PySimpleGUI as sg
month = ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
week = ["周六","周日","周一","周二","周三","周四","周五"]
layout = [[sg.In(key='-In-'),sg.CalendarButton(button_text="日历选择器",
target=('-In-'),
close_when_date_chosen=False,
# default_date_m_d_y=(1,20,2020),
default_date_m_d_y=(1,None,2020),
# locale=None,
format="%Y-%m-%d %H:%M:%S",
# begin_at_sunday_plus=0, #(星期天)
# begin_at_sunday_plus=1,#(星期一)
begin_at_sunday_plus=2,#(星期二)
# begin_at_sunday_plus=-1,#(星期六)
month_names=month, # 默认是英文
day_abbreviations=week,
title="choose Date", # 日历选择器对话框的标题
no_titlebar=False,
location=(0,0)
)]]
window = sg.Window("pthon GUI", layout, keep_on_top=True, resizable=True)
result = True
while True:
event, value = window.read()
print(event)
if event==None:
break
if event == "-In-":
window['-ccb-'].update(button_color=('white',value['-In-']))
window.close()
import PySimpleGUI as sg
month = ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
week = ["周六","周日","周一","周二","周三","周四","周五"]
layout = [[sg.Cancel(),
sg.Exit(),
sg.Help(),
sg.No(),
sg.Ok(),
sg.OK(),
sg.Open(),
sg.Quit(),
sg.Save(),
sg.Submit(),
sg.Yes(),
sg.SaveAs(),
]]
window = sg.Window("pthon GUI", layout, keep_on_top=True, resizable=True)
result = True
while True:
event, value = window.read()
print(event)
if event==None:
break
if event == "-In-":
window['-ccb-'].update(button_color=('white',value['-In-']))
window.close()
import PySimpleGUI as sg
def CB(button_text):
return [sg.B(button_text=button_text,size=(10,1),font=("黑体",12))]
layout = [CB("确定"),
CB("提交"),
CB("退出"),
CB("修改"),
]
window = sg.Window("pthon GUI", layout, keep_on_top=True, resizable=True)
result = True
while True:
event, value = window.read()
print(event)
if event==None:
break
if event == "-In-":
window['-ccb-'].update(button_color=('white',value['-In-']))
window.close()
准备工作:
pip install pandas,xlrd,xlwt,lxml,openpyxl
import pandas as pd 导入库
# 4、创建 DataFrame 二维数据表
df=pd.DataFrame([['']]) # 一行数据
df=pd.DataFrame([['','']]) # 一行数据
df=pd.DataFrame([[''],['']]) # 两行数据
df.to_excel(exel_path) # 将文件写入指定路径(包含文件名例:test.xlsx)