Created
August 4, 2020 13:29
-
-
Save weslleyspereira/e8feeb9f1b7008ae1ffad2777e39d0dd to your computer and use it in GitHub Desktop.
Tkinter toggle button to switch microphone On/Off using a script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
''' switchHeadphones.py | |
Tkinter toggle button to switch microphone On/Off using a script | |
Modification of the solution proposed in | |
https://www.daniweb.com/posts/jump/1909448 | |
for the Mic On/Off script from | |
https://gist.github.com/OndraZizka/2724d353f695dacd73a50883dfdf0fc6 | |
''' | |
# Define the path for the script below, e.g., | |
script = "./switchHeadphones.sh" | |
try: | |
# Python2 | |
import Tkinter as tk | |
except ImportError: | |
# Python3 | |
import tkinter as tk | |
import os | |
__author__ = "Weslley S Pereira" | |
__email__ = "weslley.spereira@gmail.com" | |
def toggle(tog=[0]): | |
''' | |
a list default argument has a fixed address | |
''' | |
tog[0] = not tog[0] | |
if tog[0]: | |
os.system(script+' speak') | |
t_btn.config(text='Switch Mic Off') | |
else: | |
os.system(script+' listen') | |
t_btn.config(text='Switch Mic On') | |
root = tk.Tk() | |
root.title('Headphone ') | |
t_btn = tk.Button(text='Switch Mic On', width=15, command=toggle) | |
t_btn.pack(pady=5) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@vasi786 You have to install tkinter as said by @prietopa:
Then run with: