0

I'm trying to make a program that hides and shows all my desktop files (mac) by executing defaults write com.apple.finder CreateDesktop false #or 'true' to show my files killall Finder I'm using tkinker to make a gui but everytime I execute my code, it shows all my files(without me doing anything) then when I request it to hide all my files it did, but it doesn't show them again.

Code:

import os
import tkinter as tk

def hide():
    os.system("defaults write com.apple.finder CreateDesktop false")
    os.system("killall Finder")

def show():
    os.system("defaults write com.apple.finder CreateDesktop true")
    os.system("killall Finder")

root = tk.Tk()
frame = tk.Frame(root)
frame.pack()

button = tk.Button(frame,
                    text="Hide",
                    fg="red",
                    command=hide)
button.pack(side=tk.LEFT)

slogan = tk.Button(frame,
                       text="Show",
                       fg="blue",
                       command=show())
slogan.pack(side=tk.RIGHT)

root.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

0

Change slogan to below:

slogan = tk.Button(frame,text="Show",fg="blue",command=show)

When you say command=show(), you are calling the function and hence it gets executed without you clicking the button, so instead remove the paranthesis and it will solve the problem.

Hope it cleared your doubt, if any errors do let me know

Cheers

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46