0

I have a very simple UI in Python and i want to run a Powershell Script when a Button is presed. The Problem is, that the Script is being run without pressing the button.

These are the two relevant functions:

def create_buttons(self):
    self.setup = tk.Button(self, text="Bot Setup", command=self.powershell_setup())
    self.setup.pack(side="top", pady = 10, padx = 10)
    self.quit = tk.Button(self, text="QUIT", fg="red",command=self.master.destroy)
    self.quit.pack(side="bottom")

def powershell_setup(self):
    psxmlgen = subprocess.Popen([r'C:\\WINDOWS\\system32\WindowsPowerShell\\v1.0\\powershell.exe',
                         '-ExecutionPolicy',
                         'Unrestricted',
                         './setup_bot_task.ps1'], cwd=os.getcwd())

BTW: I am using Tkinter as a GUI Framework

1 Answers1

2

The issue is here,

self.setup = tk.Button(self, text="Bot Setup", command=self.powershell_setup())

It must be (command must be a callable object):

self.setup = tk.Button(self, text="Bot Setup", command=self.powershell_setup)
mklement0
  • 382,024
  • 64
  • 607
  • 775
Abdul Niyas P M
  • 18,035
  • 2
  • 25
  • 46