我整个早上一直在寻找应该是最简单的事情,但我要么找不到合适的地方,要么不理解我所读到的所有答案。到目前为止,尝试过失败了。
我正在创建一个带有标签,文本输入框和保存按钮的对话框。用户在框中输入文本,单击保存并将文本保存到变量,对话框应关闭。我无法完成最后一点。我最接近的是破坏按钮和灰色背景,但保持面板本身完好无损。我正在寻找某种KillParent解决方案...我的主要问题是,当我点击按钮时,我需要发生两个不同的事情(保存并退出),所以当我完成后我调用on click功能变量保存我不再有控制来杀死主窗口。我知道这是非常基本的东西,但我无法弄清楚。
SELECT case when sysdate between START_DATE and END_DATE then 'Y' else 'N' end as Flag FROM EXP_ECO_RATES;
答案 0 :(得分:1)
它有点乱,但我现在没有时间清理它,它应该在showconnstring类中使用sizer。
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Dialog Test",size=(500,400))
self.panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
self.log = wx.TextCtrl(self.panel, wx.ID_ANY, size=(400,300),style = wx.TE_MULTILINE|wx.TE_READONLY|wx.VSCROLL)
self.button = wx.Button(self.panel, label="Click me")
sizer.Add(self.log, 0, wx.EXPAND | wx.ALL, 10)
sizer.Add(self.button, 0, wx.EXPAND | wx.ALL, 10)
self.panel.SetSizer(sizer)
self.Bind(wx.EVT_BUTTON, self.OnButton)
def OnButton(self,event):
dlg = ShowConnString(parent = self.panel)
dlg.ShowModal()
if dlg.result_name:
self.log.AppendText("Name: "+dlg.result_name+"\n")
self.log.AppendText("Spin: "+str(dlg.result_spin)+"\n")
self.log.AppendText("Choice: "+str(dlg.result_choice)+"\n")
else:
self.log.AppendText("No selection made\n")
dlg.Destroy()
class ShowConnString(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, wx.ID_ANY, "Save", size= (650,220))
self.panel = wx.Panel(self,wx.ID_ANY)
self.lblname = wx.StaticText(self.panel, label="Connection", pos=(20,20))
self.editname = wx.TextCtrl(self.panel, value="server=127.0.0.1", pos=(110,20), size=(500,-1))
self.lbl_1 = wx.StaticText(self.panel, wx.ID_ANY, ("Spin Control"), pos=(20,60))
self.spin = wx.SpinCtrl(self.panel, wx.ID_ANY, "", min=1, max=10, pos=(110,60))
self.lbl_2 = wx.StaticText(self.panel, wx.ID_ANY, ("Choice"),pos=(20,100))
self.choice = wx.Choice(self.panel, wx.ID_ANY, choices=[("Choice 1"), ("Choice 2"), ("Choice 3")], pos=(110,100))
self.saveButton =wx.Button(self.panel, label="Save", pos=(110,160))
self.closeButton =wx.Button(self.panel, label="Cancel", pos=(210,160))
self.saveButton.Bind(wx.EVT_BUTTON, self.SaveConnString)
self.closeButton.Bind(wx.EVT_BUTTON, self.OnQuit)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
self.spin.SetValue(0)
self.choice.SetSelection(0)
self.Show()
def OnQuit(self, event):
self.result_name = None
self.Destroy()
def SaveConnString(self, event):
self.result_name = self.editname.GetValue()
self.result_spin = self.spin.GetValue()
self.result_choice = self.choice.GetSelection()
self.Destroy()
app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
答案 1 :(得分:0)
您似乎尝试使用wx.TextEntryDialog
对wx.Panel
进行分类
您可能会发现直接使用wx.TextEntryDialog
更简单,即
import wx
app = wx.App()
dlg = wx.TextEntryDialog(None,"Connection String:","Save","server='(local)', database='Audit', uid='sa', pwd='_PWD4sa_'")
dlg.SetSize((600,180))
if dlg.ShowModal() == wx.ID_OK:
text = dlg.GetValue()
print text
dlg.Destroy()