Python Forum
[Tkinter] Exit function in Python on Ubuntu - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Exit function in Python on Ubuntu (/thread-31708.html)



Exit function in Python on Ubuntu - aalish - Dec-29-2020

Hey, I am using python3 in Ubuntu20.04 for making GUI of python programs. There are approax 5 functions in otherwords 5 .py files in a complete script. I have made button against each and they are ruuing fine. Once I start calling 1 file in GUI it start running and once it ends it create trouble. How can I exit a particular function in a complete script such that rest of the tabs are not disturbed after quiting first one. I have posted code.

Best Regards

#!/usr/bin/env python3
import tkinter as tk
import subprocess
import tkinter.messagebox
import os


path = '/home/arooj/hacker.png'

HEIGHT = 500
WIDTH = 700

root = tk.Tk()
root.title("GPS JAMMER")

background_image = tk.PhotoImage(file = "/home/arooj/hacker.png")
label= tk.Label(image = background_image)
label.pack()

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH, bg= "#2b388f")
canvas.pack()

frame = tk.Frame(root, bg= "#2b388f", bd=5, highlightbackground="black", highlightthickness=1)
frame.place(relx=0.5, rely=0.1, relwidth=0.37, relheight=0.1, anchor='n')

label = tk.Label(frame, text= "GPS Jamming Techniques", bg= "#2b388f")
label.config(font=("Arial",22, 'bold'))
label.place(rely=0.22, relx='0.10')

lower_frame = tk.Frame(root, bg= '#2b388f', bd='10', highlightbackground="black", highlightthickness=1)
lower_frame.place(relx=0.47, rely=0.34, relwidth=0.25, relheight=0.08, anchor='n')

def change_color():
    current_color = button.cget("background")
    next_color = "blue" if current_color == "#5d6d7e" else "#5d6d7e"
    button.config(background=next_color)
    root.after(1000, change_color)

def run():
	subprocess.call('./barrage.py', shell=True)

button = tk.Button(lower_frame, text= "Start", bg= "#2b388f", fg= "white", command= run)
button.place(height='27', width='55', relx='0.80', rely='0.17')
change_color()

label = tk.Label(lower_frame, text= "Barrage Jammer", bg= "#2b388f")
label.config(font=("Comic Sans",12, 'bold'))
label.place(rely=0.2, relx='0.01')

lower_frame1 = tk.Frame(root, bg= '#2b388f', bd='10', highlightbackground="blue", highlightthickness=1)
lower_frame1.place(relx=0.45, rely=0.23, relwidth=0.25, relheight=0.07, anchor='n')

label = tk.Label(lower_frame1, text= "Click to choose GPS Jammer ", bg= "#2b388f")
label.config(font=("Comic Sans",12, 'bold'))
label.place(rely=0.20, relx='0.02')

lower_frame = tk.Frame(root, bg= '#2b388f', bd='10', highlightbackground="black", highlightthickness=1)
lower_frame.place(relx=0.47, rely=0.45, relwidth=0.25, relheight=0.08, anchor='n')

def change_color():
    current_color = button.cget("background")
    next_color = "blue" if current_color == "#5d6d7e" else "#5d6d7e"
    button.config(background=next_color)
    root.after(1000, change_color)

def run():
	subprocess.call('./tone_block.py', shell=True)

button = tk.Button(lower_frame, text= "Start", bg= "#2b388f", fg= "white", command= run)
button.place(height='27', width='55', relx='0.80', rely='0.17')
change_color()

label = tk.Label(lower_frame, text= "Tone Jammer", bg= "#2b388f")
label.config(font=("Comic Sans",12, 'bold'))
label.place(rely=0.2, relx='0.01')


lower_frame = tk.Frame(root, bg= '#2b388f', bd='10', highlightbackground="black", highlightthickness=1)
lower_frame.place(relx=0.47, rely=0.56, relwidth=0.25, relheight=0.08, anchor='n')

def change_color():
    current_color = button.cget("background")
    next_color = "blue" if current_color == "#5d6d7e" else "#5d6d7e"
    button.config(background=next_color)
    root.after(1000, change_color)

def run():
	subprocess.call('./Successive.py', shell=True)

button = tk.Button(lower_frame, text= "Start", bg= "#2b388f", fg= "white", command= run)
button.place(height='27', width='55', relx='0.80', rely='0.17')
change_color()

label = tk.Label(lower_frame, text= "Successive Pulse Jammer", bg= "#2b388f")
label.config(font=("Comic Sans",12, 'bold'))
label.place(rely=0.2, relx='0.01')

lower_frame = tk.Frame(root, bg= '#2b388f', bd='10', highlightbackground="black", highlightthickness=1)
lower_frame.place(relx=0.47, rely=0.67, relwidth=0.25, relheight=0.08, anchor='n')

def change_color():
    current_color = button.cget("background")
    next_color = "blue" if current_color == "#5d6d7e" else "#5d6d7e"
    button.config(background=next_color)
    root.after(1000, change_color)

def run():
	subprocess.call('./protocol.py', shell=True)

button = tk.Button(lower_frame, text= "Start", bg= "#2b388f", fg= "white", command= run)
button.place(height='27', width='55', relx='0.80', rely='0.17')
change_color()

label = tk.Label(lower_frame, text= "Protocol Aware Jammer", bg= "#2b388f")
label.config(font=("Comic Sans",12, 'bold'))
label.place(rely=0.2, relx='0.01')

root.mainloop()



RE: Exit function in Python on Ubuntu - ndc85430 - Dec-29-2020

Why are you using subprocess to run separate Python programs like this? That seems overcomplicated. Instead those programs should be organised into functions (and classes where appropriate) that can be imported and used in this one.


RE: Exit function in Python on Ubuntu - aalish - Dec-29-2020

(Dec-29-2020, 07:39 AM)ndc85430 Wrote: Why are you using subprocess to run separate Python programs like this? That seems overcomplicated. Instead those programs should be organised into functions (and classes where appropriate) that can be imported and used in this one.

Then how can I make change in this code


RE: Exit function in Python on Ubuntu - ndc85430 - Dec-29-2020

You're going to need to show the rest of the code if you want more specific advice. Again, the basic advice still stands: organise those other programs into functions and classes that can be called from the main one.


RE: Exit function in Python on Ubuntu - aalish - Dec-29-2020

(Dec-29-2020, 08:41 AM)ndc85430 Wrote: You're going to need to show the rest of the code if you want more specific advice. Again, the basic advice still stands: organise those other programs into functions and classes that can be called from the main one.
These all subprocesses are to start one by one. Once I ll start first one after that it dont get close it self rather I do it forcefully i want some quit option with it such that one subprocess quit so others remain there for processing