首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从另一个类文件调用tkinter类文件?

如何从另一个类文件调用tkinter类文件?
EN

Stack Overflow用户
提问于 2018-05-18 05:15:12
回答 1查看 1.1K关注 0票数 1

我有两个独立的文件,每个文件都有自己定义的类。

档案1:

代码语言:javascript
运行
复制
class AndorCameraSDK:
    def __init__(self):
             self.count = 0 
    def LiveAcquisition(self,nframes,np.ndarray[np.unit16_t,ndim = 3,mode = 'c']image:
             cdef unsigned char * pBuf #This has the data
             #.......Initialisation of parameters..............#
             for i in range(nframes):
                     pBuf = <unsigned char *>calloc(sizeinBytes,sizeof(unsigned char)
                     #-----Storing the data in pBuf into a 3-D array image....#
                     pus_image = <unsigned short*> pBuf
                     for j in range(self.width):
                         pus_image = <unsigned short*> pBuf
                         for k in range(self.height):
                             image[i][j][k] = pus_image[0]
                             pus_image += 1
                         _puc_image += self.stride
  def function1(self):
             #Something else to be done with another function

在文件2中

代码语言:javascript
运行
复制
import AndorCameraSDK as andorcamera
class AndorCameraGUI:
     def __init__(self):
           #Making use of Tkinter couple of widgets has been created, which includes a button named LiveImage which calls the function LiveImageGUI.
     def LiveImageGUI (self):
           self.camera = andorcamera()
           #define a 3D array I
           self.camera.LiveAcquisition(nframes,I) #called from File 1
     def LivePlot(self)
          # A function using FigurecanvasTkAgg to display the image processed from LiveAcquisition in the display area defined in the GUI panel

我想达到的目标是:

  1. 要将pBuf存储到3D数组中的for循环必须是线程在同一数组中调用的函数。
  2. 该函数应该从文件2中调用LivePlot函数,以便将存储的图像帧显示在GUI中。
  3. 这两种情况都应该发生,在处理(i+1)st帧时,显示i第四帧,这样就不会有时间延迟。

有人能帮我一下吗?任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2018-05-18 10:39:49

我没有线程处理的经验,但是我在您的代码中没有看到线程的证据。我整理了关于缩进和删除超级代码的代码。左边是代码,说明了如何在类之间调用函数。

代码语言:javascript
运行
复制
from tkinter import *

class AndorCameraSDK():
    def __init__(self, master):
        print('SDK Init') # Show that AndorCameraSDK.__init__ runs
        self.master = master         # Save reference to master

    def LiveAcquisition(self):
        print('SDK LiveAcquisition') # Show that AndorCameraSDK.LiveAcquisition runs
        pBuf = 'Some data'       # Dummy data
        self.master.LivePlot() # Call instance of AndorCameraGUI.LivePlot

class AndorCameraGUI():
    def __init__(self):
        print('GUI Init') # Show that AndorCameraGUI.__init__ runs

    def LiveImageGUI(self):
        print('GUI LiveImageGUI') # Show that AndorCameraGUI.LiveImageGUI runs
        self.camera = AndorCameraSDK(self) # Create instance of AndorCameraSDK
        self.camera.LiveAcquisition() # Call AndorCameraSDK.LiveAcquisition

    def LivePlot(self):
        print('GUI LivePlot') # Show that AndorCameraGUI.LivePlot runs

app = AndorCameraGUI()
app.LiveImageGUI()  # Instead of pressing a button
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50404195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档