[英]Using C application with a Python GUI
I have built a simple application in C and I want it to have a GUI. 我已经用C构建了一个简单的应用程序,并且希望它具有GUI。 I want the GUI to be in Python (since it's easier) but am not sure how I would get the user response from Python to C or even if it's possible.
我希望GUI使用Python(因为它更容易),但是不确定如何将用户响应从Python转换为C,甚至是不可能的。
What I want is a tkinter window to open asking if the user wants to play a file and if they click on yes then for the file get played. 我想要的是打开一个tkinter窗口,询问用户是否要播放文件,是否单击是,然后播放文件。
This is my C script (main_file.c): 这是我的C脚本(main_file.c):
#include <window.h>
#include <stdio.h>
#include <conio.h>
#include <python.h>
int Play()
{
PlaySound("Sound1.wav", NULL, SND_ASYNC);
while(1)
{
continue;
}
return 0;
}
int main()
{
char filename[] = "GUI.py";
FILE* fp;
Py_Initialize();
fp = _Py_fopen(filename, "r");
PyRun_SimpleFile(fp, filename);
Py_Finalize();
return 0;
}
and my GUI.py file: 和我的GUI.py文件:
import tkinter as tk
class App(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.pack()
self.option()
def option(self):
self.opt = tk.Button(self)
self.opt["text"] = "Do You Want To Play File"
self.opt["command"] = self.play
self.opt.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red", command=root.destroy)
self.quit.pack(side="bottom")
def play(self):
#This part needs to tell C to use Play() function
root = tk.Tk()
app = App(master=root)
app.mainloop()
The problem is that I don't know how to make Python tell C to use the Play() function. 问题是我不知道如何让Python告诉C使用Play()函数。
I'm using MinGW on Windows 10. 我在Windows 10上使用MinGW。
编译main_file.c并使用以下os.system(r'PATH_TO_EXE')
作为可执行文件运行: os.system(r'PATH_TO_EXE')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.