0

I am creating a tool to filter a profile based on skills and then finally open a word document with detailed information on the selected profile.

I am using Tkinter to show the dropdown menu for each filter.

Below is my Code:

from tkinter import *
from pandas import * 
import os

root=Tk()
root.title('Skill Search Tool')

def getProfile():
    
    os.system("SelectedProfile.docx")


ProfileGet= Button(root,text="Get Profile",command=getProfile())
ProfileGet.pack()


root.mainloop()

However when I click on the button, nothing happens.

Can anyone guide me here?

Regards, Chinmay

JMW
  • 261
  • 2
  • 7
  • You need to pass the function reference `command=getProfile`, not the result of the function `command=getProfile()`. – acw1668 Jun 26 '20 at 05:34
  • Also better use `os.startfile(...)` instead of `os.system(...)` in your case if your platform is Windows. – acw1668 Jun 26 '20 at 05:44
  • I am working on a Mac. I tried to change the code from command=getProfile() to command=getProfile and the function definition to def getProfile(): name="SelectedProfile.docx" os.system(name) but now I am getting another error when I click on the button. sh: SelectedProfile.docx: command not found – Chinmay Narwane Jun 26 '20 at 06:59
  • It is because `os.system()` will treat `SelectedProfile.docx` as command. As I don't know about MacOS, you need to find a way to open the .docx using default program. – acw1668 Jun 26 '20 at 07:07
  • Maybe [is-there-an-platform-independent-equivalent-of-os-startfile](https://stackoverflow.com/questions/17317219/is-there-an-platform-independent-equivalent-of-os-startfile) is helpful. – acw1668 Jun 26 '20 at 07:13

1 Answers1

1

You are calling the function getProfiles when you add the brackets to the end which means it will run as soon as your program starts, instead you can simply write...

ProfileGet= Button(root,text="Get Profile",command=getProfile)

However, if in the future you wish to pass parameters to your function you may want to use a lambda function...

ProfileGet= Button(root,text="Get Profile",command=lambda: getProfile(arg1,arg2))
A.Goody
  • 71
  • 1