admin管理员组文章数量:1122832
I have been making a gui app using dearpygui and I ran into a weird problem when adding labels to checkboxes. For some reason it wont show the character "#" in the labels. I am trying to assign music notes to each checkbox through recursive looping and that includes sharps so I cant just overlook it. I thought at first that maybe it was a data type problem but ruled that out pretty quick seeing as the program still ran and displayed labels but the letters only.
Here is the full code for the program:
import dearpygui.dearpygui as dpg
import numpy as np
def save_callback():
print("Save Clicked")
def note_esp():
return
note = np.array([["E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D"],
["A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G"],
["D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C"],
["G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F"],
["B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A"],
["E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D"]])
dpg.create_context()
dpg.show_style_editor()
dpg.create_viewport(title="MAIN VIEWPORT",width=1000, height=800)
dpg.setup_dearpygui()
with dpg.window(tag="Primary Window"):
dpg.add_text("WELCOME TO YOUR FRETBOARD")
with dpg.table(header_row=False):
for l in range(0,12):
dpg.add_table_column()
for i in range(0, 1):
with dpg.table_row():
for j in range(0, 12):
dpg.add_checkbox(label=note[0][j],tag=("cb"+str(j)))
dpg.add_button(label="Save", callback=save_callback)
dpg.add_input_text(label="string")
dpg.add_slider_float(label="float")
with dpg.table(header_row=False):
for k in range(0,23):
dpg.add_table_column()
for i in range(0, 6):
with dpg.table_row():
for j in range(0, 23):
dpg.add_text(note[i][j])
dpg.show_viewport()
dpg.set_primary_window("Primary Window",True)
dpg.start_dearpygui()
dpg.destroy_context()
Here is a screenshot of my output for the program:
The red bit is the particular feature I'm focusing on.
I couldn't find any existing cases of people having this problem so I'm assuming this is a "me problem" to an extent. Any and all information is welcome
I have been making a gui app using dearpygui and I ran into a weird problem when adding labels to checkboxes. For some reason it wont show the character "#" in the labels. I am trying to assign music notes to each checkbox through recursive looping and that includes sharps so I cant just overlook it. I thought at first that maybe it was a data type problem but ruled that out pretty quick seeing as the program still ran and displayed labels but the letters only.
Here is the full code for the program:
import dearpygui.dearpygui as dpg
import numpy as np
def save_callback():
print("Save Clicked")
def note_esp():
return
note = np.array([["E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D"],
["A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G"],
["D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C"],
["G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F"],
["B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A"],
["E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D"]])
dpg.create_context()
dpg.show_style_editor()
dpg.create_viewport(title="MAIN VIEWPORT",width=1000, height=800)
dpg.setup_dearpygui()
with dpg.window(tag="Primary Window"):
dpg.add_text("WELCOME TO YOUR FRETBOARD")
with dpg.table(header_row=False):
for l in range(0,12):
dpg.add_table_column()
for i in range(0, 1):
with dpg.table_row():
for j in range(0, 12):
dpg.add_checkbox(label=note[0][j],tag=("cb"+str(j)))
dpg.add_button(label="Save", callback=save_callback)
dpg.add_input_text(label="string")
dpg.add_slider_float(label="float")
with dpg.table(header_row=False):
for k in range(0,23):
dpg.add_table_column()
for i in range(0, 6):
with dpg.table_row():
for j in range(0, 23):
dpg.add_text(note[i][j])
dpg.show_viewport()
dpg.set_primary_window("Primary Window",True)
dpg.start_dearpygui()
dpg.destroy_context()
Here is a screenshot of my output for the program:
The red bit is the particular feature I'm focusing on.
I couldn't find any existing cases of people having this problem so I'm assuming this is a "me problem" to an extent. Any and all information is welcome
Share Improve this question edited Nov 23, 2024 at 19:57 Mylek Dynamics asked Nov 23, 2024 at 4:37 Mylek DynamicsMylek Dynamics 114 bronze badges 2- We can't really help without a minimal reproducible example. That is something that is both way shorter and way longer that your current code. Shorter because we don't need all these details of arrays and stuff. Reduce the problem to a single checkbox with a hard-coded label (there are lot of chance that, while doing so, you will find the real problem and may its solution yourself), Longer because your code illustrating the problem should work standalone. I should be able to copy&paste your code in my python interpreter, and see for myself the problem, and then try to solve it. – chrslg Commented Nov 23, 2024 at 11:00
- That was an oversight, I added in the full source code. – Mylek Dynamics Commented Nov 23, 2024 at 20:01
1 Answer
Reset to default 0Note that adding the full code was not what I was asking. You are expected to reduce it to the minimal part illustrating the problem. It is very easy, here, to see that the problem can be reduced to
import dearpygui.dearpygui as dpg
dpg.create_context()
with dpg.window():
dpg.add_checkbox(label=r"A#")
dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
That is what we call a minimal reproducible example. And that is what askers are supposed to do, to post. Now, the question is way clearer. There is no doubt that this has nothing to do with numpy. Nor with arrays
At first glance, documentation doesn't clearly states that you can't use #
. But it does mention the fact that things following a pair of #
is not part of the displayed label (it is a tag, or whatever).
So, since doesn't happen with any other ascii chars than the #
, and even, only #
at the end of the string, it is obvious to me (but I don't have official source to back that guess) that this is related.
Maybe it is just a bug in the code that parse label to search tag after ##
and skip everything after ##
for display.
Something like a
for(;;){
c=getchar(); if(eof(c)) break;
if(c=='#'){
c=getchar(); if(eof(c)) break;
if(c=='#'){
tag=gettag();
break;
}
}else display(c);
That forgets the case of #
ending the string. Or maybe there is another reason.
Whatever it is, it is easy to realize that two #
are not displayed, and the rest of the string is ignored (that is documented)
That one #
is displayed. Unless it is the last char of the string.
So some workaround here:
You could use another char for the #
.
I would suggest ♯
(which is probably even better that #
for your application, since I take it is related to music, and that is the music ♯).
But on my PC, this isn't displayed. Dearpygui is quite bugged (each time I use it, I manage to seg fault it in a few lines, with just python code. Each time, it is my fault, of course. I forget some init somewhere. But a python library is not supposed to segfault the whole thing when we do some mistake. Now, there is this #
thing. And unicode rendering is famoulsly very poor — after all, it has only been a few decades since unicode is the standard of all major OS ; we have to let them some more time...).
But maybe on your system, that ♯ will be correctly rendered.
Another thing you could try, is to add something else after. For example a 0 width space "A#\u200b"
. But there again, poor unicode support. On my machine (I say "on my machine", since this is a bug, and maybe more recent version works better. Plus, maybe this is dependent on installed fonts), it displays a ugly "?"
The failsafe, if that is acceptable to you, is to add a pure ascii space after the #
So "A# "
本文标签: pythonHow to display special characters in DearPyGui Checkbox LabelStack Overflow
版权声明:本文标题:python - How to display special characters in DearPyGui Checkbox Label? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299826a1930598.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论