简体   繁体   中英

import a tkinter widget in wxpython application as a panel

I created a analog rpm gauge using the canvas widget of Tkinter and I want to import it in a wx GUI application (as a panel, maybe). Is there any way to do it or I must rewrite this widget in wx?

There is no (simple) way to do that - WxWidgets is an abstraction over different toolkits in different systems, and use different mainloop functions, while Tkinter has its own mainloop - that is to start with.

So making that work would at leas require:

  1. that you'd setup different threads able to run both mainloops in paralell,
  2. finding a way to get Tkinter to render the widget to an in memory bitmap
  3. create a custom widget in wx which would render that bitmap to the screen
  4. and map events on it back to Tkinter, if it is supposed to respond events

So you are definitely better of writting the widget again.

WxPython有一个速度计小部件,而不是使用它。

import wx.lib.agw.speedmeter

You would have to rewrite the widget in wxPython or find a widget that does the same thing that's already included with wx. Tkinter is a completely different GUI toolkit that draws its own widgets and is based on TCL whereas wxPython is a wrapper around wxWidgets which is based on C++. There is no easy way to embed a widget from Tkinter into wxPython.

As Yoriz mentioned, you might be able to use the speedmeter widget in wxPython. Check out the wxPython demo package as it will show you how to use that widget and most of wxPython's other widgets. Hopefully you can find something that's already included. Otherwise, you may want to take a look at the following page:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM