是否可以从from Tkinter import *
from websocket import *
from threading import *
master = Tk()
master.wm_title("Team Black Client")
master.withdraw()
minwidth = master.winfo_screenwidth()/4*3
minheight = master.winfo_screenheight()/4*3
master.minsize(width=minwidth, height=minheight)
x = (master.winfo_screenwidth() - minwidth)/2
y = (master.winfo_screenheight() - minheight)/2
master.geometry("+"+str(x)+"+"+str(y))
master.deiconify()
master.resizable(0,0)
text = Text(master)
text.pack(expand=True,fill=BOTH)
def on_message(ws, message):
text.insert(END, message+"\n")
print "Received: "+message
return
def on_error(ws, error):
text.insert(END, error+"\n")
print error
return
def on_close(ws):
text.insert(END, "### closed ###\n")
print "### closed ###"
return
def on_open(ws):
ws.send("hi")
ws.send("test")
return
def connection():
enableTrace(True)
ws = WebSocketApp("ws://echo.websocket.org/", on_message = on_message, on_error = on_error, on_close = on_close)
ws.on_open = on_open
ws.run_forever()
return
t = Thread(target=connection)
t.start()
master.mainloop()
加载网址而不将其附加到任何布局(不可见)?
答案 0 :(得分:5)
是的,您可以使用应用程序上下文来实例化WebView:
WebView webView = new WebView(getApplicationContext());
webView.loadUrl("your-url");
令人惊讶的是,这有效......这意味着实际上可以使用应用程序上下文创建webview,并且不需要UI上下文,这对我来说有点奇怪。