创建gui窗口

This commit is contained in:
ranchuan
2025-06-17 19:11:48 +08:00
commit 2be23d5540
5 changed files with 141 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.spec
build/
dist/

71
dbg_main1.py Normal file
View File

@@ -0,0 +1,71 @@
import dearpygui.dearpygui as dpg
def print_me(sender,app_data):
print(f"Menu Item: {sender} value={dpg.get_value(sender)} app_data={app_data}")
dpg.create_context()
# add a font registry
with dpg.font_registry():
with dpg.font("simfang.ttf", 20) as font1:
# add the default font range
dpg.add_font_range_hint(dpg.mvFontRangeHint_Default)
# helper to add range of characters
# Options:
# mvFontRangeHint_Japanese
# mvFontRangeHint_Korean
# mvFontRangeHint_Chinese_Full
# mvFontRangeHint_Chinese_Simplified_Common
# mvFontRangeHint_Cyrillic
# mvFontRangeHint_Thai
# mvFontRangeHint_Vietnamese
dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
# add specific range of glyphs
dpg.add_font_range(0x3100, 0x3ff0)
# add specific glyphs
dpg.add_font_chars([0x3105, 0x3107, 0x3108])
# remap や to %
dpg.add_char_remap(0x3084, 0x0025)
# set font of specific widget
dpg.bind_font(font1)
with dpg.window(tag="Primary Window"):
dpg.add_text("Hello, world")
dpg.add_button(label="保存",callback=print_me)
dpg.add_input_text(label="string", default_value="示例文本",callback=print_me)
dpg.add_slider_float(label="float", default_value=0.273, max_value=1,callback=print_me)
with dpg.menu_bar(parent="Primary Window"):
with dpg.menu(label="文件"):
dpg.add_menu_item(label="打开", callback=lambda : dpg.show_item('file_dialog'))
dpg.add_menu_item(label="另存为", callback=print_me)
with dpg.menu(label="设置"):
dpg.add_menu_item(label="设置项1", callback=print_me, check=True)
dpg.add_menu_item(label="设置项2", callback=print_me)
dpg.add_menu_item(label="帮助", callback=print_me)
with dpg.menu(label="窗口条目"):
dpg.add_checkbox(label="勾选", callback=print_me)
dpg.add_button(label="点击", callback=print_me)
dpg.add_color_picker(label="选择颜色", callback=print_me)
with dpg.file_dialog(label="选择文件", directory_selector=False, show=False, callback=print_me,width=700,height=500,
file_count=1,default_path='./',tag='file_dialog'):
dpg.add_file_extension(".*")
dpg.add_file_extension("", color=(150, 255, 150, 255))
dpg.add_file_extension("Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp}", color=(0, 255, 255, 255))
dpg.add_file_extension(".h", color=(255, 0, 255, 255), custom_text="[header]")
dpg.add_file_extension(".py", color=(0, 255, 0, 255), custom_text="[Python]")
dpg.create_viewport(title='Custom Title', width=1000, height=700, resizable=False)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.set_primary_window("Primary Window", True)
dpg.start_dearpygui()
dpg.destroy_context()

37
dpg_font.py Normal file
View File

@@ -0,0 +1,37 @@
import dearpygui.dearpygui as dpg
dpg.create_context()
with dpg.font_registry():
with dpg.font("simfang.ttf", 20) as font1:
# add the default font range
dpg.add_font_range_hint(dpg.mvFontRangeHint_Default)
# helper to add range of characters
# Options:
# mvFontRangeHint_Japanese
# mvFontRangeHint_Korean
# mvFontRangeHint_Chinese_Full
# mvFontRangeHint_Chinese_Simplified_Common
# mvFontRangeHint_Cyrillic
# mvFontRangeHint_Thai
# mvFontRangeHint_Vietnamese
dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
# add specific range of glyphs
dpg.add_font_range(0x3100, 0x3ff0)
# add specific glyphs
dpg.add_font_chars([0x3105, 0x3107, 0x3108])
# remap や to %
dpg.add_char_remap(0x3084, 0x0025)
dpg.show_font_manager()
dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

30
dpg_main.py Normal file
View File

@@ -0,0 +1,30 @@
import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.create_viewport(title='Custom Title', width=600, height=200)
def print_me(sender):
print(f"Menu Item: {sender}")
with dpg.window(label="Tutorial"):
with dpg.menu_bar():
with dpg.menu(label="File"):
dpg.add_menu_item(label="Save", callback=print_me)
dpg.add_menu_item(label="Save As", callback=print_me)
with dpg.menu(label="Settings"):
dpg.add_menu_item(label="Setting 1", callback=print_me, check=True)
dpg.add_menu_item(label="Setting 2", callback=print_me)
dpg.add_menu_item(label="Help", callback=print_me)
with dpg.menu(label="Widget Items"):
dpg.add_checkbox(label="Pick Me", callback=print_me)
dpg.add_button(label="Press Me", callback=print_me)
dpg.add_color_picker(label="Color Me", callback=print_me)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

BIN
simfang.ttf Normal file

Binary file not shown.