gpt4 book ai didi

python - 在显示大型机之前从对话框获取用户输入

转载 作者:太空宇宙 更新时间:2023-11-03 16:44:22 25 4
gpt4 key购买 nike

我有 wxPython GUI 程序,它必须从用户那里获取输入才能运行。我想在主框架之前显示对话框,存储输入,关闭对话框,然后运行主程序。现在我正在使用 raw_input 代替。这是我的代码:

import wx
import wx.lib.iewin as iewin
import subprocess

class MyBrowser(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id,
style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP)
self.transparency = 255

sizer = wx.BoxSizer(wx.VERTICAL)
self.browser = iewin.IEHtmlWindow(self)
sizer.Add(self.browser, 1, wx.EXPAND, 10)

self.Bind(wx.EVT_CHAR_HOOK, self.onKey)

def SetTransparent(self, value):
self.transparency = value
wx.Frame.SetTransparent(self, value)

def GetTransparent(self):
return self.transparency

def decreaseTransparency(self, e):
self.SetTransparent(self.GetTransparent() - 10)
def increaseTransparency(self, e):
self.SetTransparent(self.GetTransparent() + 10)


def onKey(self, evt):
if evt.GetKeyCode() == wx.WXK_DOWN:
self.decreaseTransparency(self)
elif evt.GetKeyCode() == wx.WXK_UP:
self.increaseTransparency(self)
else:
evt.Skip()

def load(self,uri):
self.browser.Navigate(uri)

#starts livestreamer process
response = raw_input("Livestreamers name:\n")
livestreamer = "livestreamer twitch.tv/"
host = subprocess.Popen(['livestreamer', 'twitch.tv/'+response, 'best'], stdout=subprocess.PIPE)

if __name__ == '__main__':
app = wx.App()
dialog = MyBrowser(None, -1)
dialog.browser.Navigate("https://www.twitch.tv/" + response+ "/chat?popout=")
dialog.Show()
app.MainLoop()
host.communicate()[0]

这就是我的想法: dialog example

最佳答案

在浏览器中创建一个对话框,在其上运行ShowModal,然后使用dialog.GetValue获取输入

class MyBrowser(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id,
style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP)
self.transparency = 255
self.dialog = wx.TextEntryDialog(None, message="Enter stuff")
self.dialog.ShowModal()
print self.dialog.GetValue()
self.Bind(wx.EVT_CHAR_HOOK, self.onKey)

显然将打印它替换为您想要对值执行的任何操作

如果您想在 MyBrowser 对象实例化后访问它,请将其指定为实例变量而不是打印。

class MyBrowser(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id,
style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP)
self.transparency = 255
self.dialog = wx.TextEntryDialog(None, message="Enter stuff")
self.dialog.ShowModal()
self.dlg_val = self.dialog.GetValue()
self.Bind(wx.EVT_CHAR_HOOK, self.onKey)

然后继续往下使用

if __name__ == "__main__":
dialog = MyBrowser(None)
print dialog.dlg_val

关于python - 在显示大型机之前从对话框获取用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36462432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com