Button does not perform a function when clicked

Asked

Viewed 61 times

2

Good night

I’m working with the TKINTER library and OS in Python. And I want that when I click the RUN button, the.py program will run my.BAT file.

But the.BAT file runs as soon as the.py program starts without the click.

How do I solve this problem?

Thanks in advance.

Follows the code

Note: The TEST script that I am importing is my module that is using the OS library to fetch the.BAT file


from tkinter import *

import teste

class aplication(Frame):

    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.widget1 = Frame()
        self.widget1.pack()

        self.msg = Label(self.widget1, text='Problema relacionado a internet? ')
        self.msg.pack()

        self.BtnInternet = Button(self.widget1)
        self.BtnInternet["text"] = "Executar"
        self.BtnInternet.bind("<Button-1>", self.chamarbat)
        self.BtnInternet.pack()


    def chamarbat(self, event):
        return teste

root = Tk()

aplication(root)

root.mainloop()

script Test.py

import os

filepath = 'C:/Users/Pc1/PycharmProjects/.BAT_SweetMix/renew.bat'

dirs = os.startfile(filepath)
  • Place the contents of test py. in a function: def execFile(): dirs = os.startfile(filepath) then call her: def chamarbat(self, event): return teste.execFile()

  • It worked. Thank you very much. It makes total sense to put the test.py in one function

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.