dear pygui ver_1.0.2【中文字体、创建窗口】

安装

pip install dearpygui

python > 3.6
ver 1.0.2 (2021.10)

加载中文字体

下载otf ttf 字体到项目文件夹

import dearpygui.dearpygui as dpg

dpg.create_context()
with dpg.font_registry(): #注册字体,自选字体
    with dpg.font("CN.otf", 20) as font1:	#增加中文编码范围,防止问好
          dpg.add_font_range_hint(dpg.mvFontRangeHint_Default)
          dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Simplified_Common)
          dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
 #       mvFontRangeHint_Japanese
 #       mvFontRangeHint_Korean
 #       mvFontRangeHint_Cyrillic
 #       mvFontRangeHint_Thai
#        mvFontRangeHint_Vietnamese
    

加入窗口

with dpg.window(label="demo", width=500, height=150):
    dpg.add_text("Hello, world")
    dpg.add_text("你好,世界")
    dpg.bind_font(font1)
#demo 完整代码
import dearpygui.dearpygui as dpg

dpg.create_context()
with dpg.font_registry(): #注册字体,自选字体
    with dpg.font("CN.otf", 20) as font1:	#增加中文编码范围,防止问好
          dpg.add_font_range_hint(dpg.mvFontRangeHint_Default)
          dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Simplified_Common)
          dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
 #       mvFontRangeHint_Japanese
 #       mvFontRangeHint_Korean
 #       mvFontRangeHint_Cyrillic
 #       mvFontRangeHint_Thai
#        mvFontRangeHint_Vietnamese

with dpg.window(label="demo", width=500, height=150):
    dpg.add_text("Hello, world")
    dpg.add_text("你好,世界")
    dpg.bind_font(font1)
    
dpg.create_viewport(title="dear_pygui", width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

在这里插入图片描述

补充

  1. 字体
with dpg.font_registry():
    with dpg.font("CN.otf", 20) as font1:
    ...
    with dpg.font("star.otf", 20) as font2:
    ...

控件指定字体设置

a = dpg.add_text("你好,世界")
b = dpg.add_text("hello world")
#dpg.bind_font(font1)  #全控件指定font字体
# 多控件指定不同字体
dpg.bind_item_font(a, font1)
dpg.bind_item_font(b, font2)	

在这里插入图片描述

  1. with dpg.window()

windows窗口设置

label (str, optional):将“名称”替换为标签。
user_data (Any, optional): 回调的用户数据
use_internal_label (bool, optional): 使用生成的内部标签而不是用户指定的标签(附录uuid)。
tag (Union[int, str], optional): 用于以编程方式引用项的唯一id。如果标签未使用,则将是标签。
width (int, optional): 项目的宽度。
height (int, optional): 项目的高度。
indent (int, optional): 将小部件向右偏移指定的数字乘以缩进样式。
show (bool, optional): 尝试呈现小部件。
pos (Union[List[int], Tuple[int, ...]], optional): 相对于窗口坐标放置项目,[0,0]位于左上角。
delay_search (bool, optional): Delays searching container for specified items until the end of the app. Possible optimization when a container has many children that are not accessed often.
min_size (Union[List[int], Tuple[int, ...]], optional): Minimum window size.
max_size (Union[List[int], Tuple[int, ...]], optional): Maximum window size.
menubar (bool, optional): Shows or hides the menubar.
collapsed (bool, optional): Collapse the window.
autosize (bool, optional): Autosized the window to fit it's items.
no_resize (bool, optional): Allows for the window size to be changed or fixed.
no_title_bar (bool, optional): Title name for the title bar of the window.
no_move (bool, optional): Allows for the window's position to be changed or fixed.
no_scrollbar (bool, optional):  Disable scrollbars. (window can still scroll with mouse or programmatically)
no_collapse (bool, optional): Disable user collapsing window by double-clicking on it.
horizontal_scrollbar (bool, optional): Allow horizontal scrollbar to appear. (off by default)
no_focus_on_appearing (bool, optional): Disable taking focus when transitioning from hidden to visible state.
no_bring_to_front_on_focus (bool, optional): Disable bringing window to front when taking focus. (e.g. clicking on it or programmatically giving it focus)
no_close (bool, optional): Disable user closing the window by removing the close button.
no_background (bool, optional): 将背景和边框alpha设置为透明。
modal (bool, optional): Fills area behind window according to the theme and disables user ability to interact with anything except the window.
popup (bool, optional): Fills area behind window according to the theme, removes title bar, collapse and close. Window can be closed by selecting area in the background behind the window.
no_saved_settings (bool, optional): Never load/save settings in .ini file.
on_close (Callable, optional): Callback ran when window is closed.
id (Union[int, str], optional): (deprecated) 

pos坐标,no_background无边框无背景

with dpg.window(label="demo", width=500, height=150,pos=[20,20],no_background=True):
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值