Dearpygui的MessageBox
我正在使用DearpyGui库在Python中创建用户界面。
在运行我的算法的函数中,该算法需要用户的一些输入(是/否问题)。是否可以在不制动功能流程的情况下轻松地在DearpyGui中实现此类消息框?
类似的事情:
def runAlgorithm():
a = 2 + 2
user_choice = dpg.messageBox("Do you want to add or subtract the values", ["add", "subtract"]
if user_choice == "add":
a = a + a
else:
a = a - a
print("The user has selected %s and the result is %d"%(user_choice, a)
正如我了解到到目前为止,这是不可能的,我必须编写类似的内容,这是相当笨重和不可读的,尤其是在可能需要某些用户输入的算法中,会大大破坏其可读性。
def choiceAdd(sender, app_data, user_data):
a = user_data[0]
print("The user has selected %s and the result is %d"%("add", a + a)
def choiceSub(sender, app_data, user_data):
a = user_data[0]
print("The user has selected %s and the result is %d"%("subtract", a - a)
def runAlgorithm():
a = 2 + 2
with dpg.window():
dpg.add_button("add", callback = choiceAdd, user_data = [a])
dpg.add_button("subtract", callback = choiceSub, user_data = [a]
user_choice = dpg.messageBox("Do you want to add or subtract the values", ["add", "subtract"]
if user_choice == "add":
a = a + a
else:
a = a - a
print("The user has selected %s and the result is %d"%(user_choice, a)
建议任何帮助。 先感谢您
I am using the DearPyGui library for creating a user interface in python.
In a function that runs my algorithm, the algorithm needs some input from the user (yes/no question). Is it possible to easily implement such a messagebox in DearPyGui without braking the flow of the function?
Something like this:
def runAlgorithm():
a = 2 + 2
user_choice = dpg.messageBox("Do you want to add or subtract the values", ["add", "subtract"]
if user_choice == "add":
a = a + a
else:
a = a - a
print("The user has selected %s and the result is %d"%(user_choice, a)
As I understand DearPyGui until now, this is not possible and I have to write something like this, which is quite bulky and unreadable and especially in algorithms that might need some user input greatly disrupts their readability.
def choiceAdd(sender, app_data, user_data):
a = user_data[0]
print("The user has selected %s and the result is %d"%("add", a + a)
def choiceSub(sender, app_data, user_data):
a = user_data[0]
print("The user has selected %s and the result is %d"%("subtract", a - a)
def runAlgorithm():
a = 2 + 2
with dpg.window():
dpg.add_button("add", callback = choiceAdd, user_data = [a])
dpg.add_button("subtract", callback = choiceSub, user_data = [a]
user_choice = dpg.messageBox("Do you want to add or subtract the values", ["add", "subtract"]
if user_choice == "add":
a = a + a
else:
a = a - a
print("The user has selected %s and the result is %d"%(user_choice, a)
Any help is recommended.
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码可能会帮助
pythonic pythonic popup messagebox in dearppygui(asyncio或sync or sync or sync or sync or sync或sync )
目标:DearpyGui
解决方案中的Pythonic Popup Message Box:
和Asyncio方式:
codes below maybe help
pythonic popup messagebox in dearpygui (asyncio or sync way)
target: pythonic popup messagebox in dearpygui
solution:
and asyncio way: