我正在使用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)
据我所知,DearPyGui到现在为止,这是不可能的,我必须写这样的东西,这是相当庞大和不可读的,特别是在算法,可能需要一些用户输入大大破坏了他们的可读性。
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)
任何帮助都值得推荐。提前感谢您
1条答案
按热度按时间v09wglhw1#
下面的代码可能会有帮助
pythonic popup messagebox in dearpygui (asyncio or sync way)
target:pythonic popup messagebox in dearpygui
解决方案:
和Pillcio方式: