简体   繁体   中英

how to bind an exe to a gui button - kivy

Allright, I just wrote a programme specific for my data analysis purposes and convert it to exe and when i double click on it, it works fine now except showing the console and all the other things it is doing. Instead double clicking on the exe file, i developped a very simple kivy gui which is as follows;

from cProfile import label
from email.mime import image
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput

class Data_Col(App):
    def build(self):
        self.window = GridLayout()
        self.window.cols = 1
        self.window.size_hint = (0.5, 0.5)
        self.window.pos_hint = {"center_x": 0.5, "center_y" : 0.5}
        # add widgets to window

        # image widget
        self.window.add_widget(Image(source="logo.png"))
        # label widget
        self.greeting = Label(text="Bonjour!!!", font_size = 18, bold = True)
        self.window.add_widget(self.greeting)
        # button widget
        self.button = Button(text="Run Data-Col", size_hint = (0.3, 0.3), bold = True, background_color = '0175E8', background_normal = "")
        self.window.add_widget(self.button)
        
        
        return self.window

if __name__ == "__main__":
    Data_Col().run()

what i want is when the user clicks on the button, it runs the exe file which is in a different folder in my pc. So i need to give a path too to the button to go and tricks the execution of exe file. But don't know how to do it, if anyone knows i would appreciate it. thanks

I don't know much about Kivy, but I can help you run an.EXE file.

This is the code I wrote:

import os

def run_exe(file): # This is the function to run
    os.system("start "+file)

run_exe("path/to/file.exe") # Replace "path/to/file.exe" with the path to your file (E.G. "C:/Users/Hipposgrumm/Documents/helloworld.exe").

Hopefully, that works. I'm more of a TKinter user so tell me if this isn't usable.

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