Wxpython - 如何在不关闭应用程序的情况下生成一系列文本提示?
我在 wxpython 中有一个文本框(见下文),它将值的名称存储为变量。
我想做两件事:
输入答案后,我想显示另一个问题,并使用相同或相同的 TextEntryDialog 窗口将新答案分配给另一个变量。
理想情况下,从用户的角度来看,他们只是看到提示,输入答案(或从列表中选择),然后点击“确定”后,提示将发生变化,他们将输入一个新答案(该答案将被分配给新变量)。
那么我为什么要尝试这样做呢?所以在本次问答结束后在会话中,我可以使用 pyodbc 将所有变量写入数据库(我现在不需要知道)。
那么您能否告诉我如何在输入答案后自动生成新提示而不关闭应用程序并丢失变量数据?无论如何,在用户接听时是否可以自动备份这些可变数据,以防应用程序崩溃?我的问题列表大约有 250 个问题,如果我的应用程序崩溃(他们往往会这样做),我不希望所有这些变量丢失,
谢谢!
import wx
class applicationName(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Title', size=(300,200))
#create panel and button
panel = wx.Panel(self)
test = wx.TextEntryDialog(None, "What's your name?", 'Title', 'Enter name')
if test.ShowModal() == wx.ID_OK:
apples = test.GetValue()
wx.StaticText(panel, -1, apples, (10,10))
if __name__ =='__main__':
app = wx.PySimpleApp()
frame = applicationName(parent=None, id=-1)
frame.Show()
app.MainLoop()
I have a text box in wxpython (see below) that stores the name of the value as a variable.
I am trying to do two things:
After the answer is entered, I want to display another question, and assign the new answer to another variable, using the same or an idential TextEntryDialog window.
Ideally, from a user standpoint, they just see a prompt, type an answer (or select from a list), and then after hitting OK, the prompt will change, and they will type in a new answer (which will be assigned to a new variable).
So why am I trying to do this? So that after the end of this Q & A session, I can write all of the variables to a database using pyodbc (which I dont need to know about right now).
So could you please tell me how I can automatically generate new prompts once an answer has been entered without closing the app and losing the variable data? And is there anyway to automatically backup this variable data while the user is answering in case the app crashes? My question list is about 250 questions long, and I dont want all those variables lost if my application crashes (which they tend to do)
Thanks!
import wx
class applicationName(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Title', size=(300,200))
#create panel and button
panel = wx.Panel(self)
test = wx.TextEntryDialog(None, "What's your name?", 'Title', 'Enter name')
if test.ShowModal() == wx.ID_OK:
apples = test.GetValue()
wx.StaticText(panel, -1, apples, (10,10))
if __name__ =='__main__':
app = wx.PySimpleApp()
frame = applicationName(parent=None, id=-1)
frame.Show()
app.MainLoop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不建议像其他人那样创建和销毁 250 个对话框。我可能会在程序开始时创建一个列表或字典,每当用户输入答案时就会附加到该列表或字典中。同样在该事件处理程序中,我将使用新问题重置 StaticText 控件。如果您的问题长度变化很大,您可能需要刷新屏幕,但我认为这比连续显示数百个对话框要好得多。
编辑 - 在下面添加了一些示例代码:
I don't recommend creating and destroying 250 dialogs like the other fellow did. I would probably create a list or dict at the beginning of my program that would get appended to whenever the user enters an answer. Also in that event handler, I would reset the StaticText control with a new question. You might need to refresh the screen if your questions vary a lot in length, but I think that would be a lot better than showing hundreds of dialogs in a row.
EDIT - Added some example code below:
您甚至可以执行类似以下操作:
getanswer
可以如下所示:questions
可以包含要传递给 wx.TextEntryDialog 构造函数的内容的列表或元组。You can even do something like:
getanswer
could look like:questions
can contain lists or tuples of the stuff you want to pass to the constructor ofwx.TextEntryDialog
.