Python Forum
How to display results from terminal window onto tkinter.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to display results from terminal window onto tkinter.
#1
Hey all.
Ive made a Tkinter frontend using the following code:
#!/usr/bin/env python3
import tkinter as tk
import subprocess
import tkinter.messagebox
import os


path = '/home/rukha/Desktop/hacker.png'

HEIGHT = 500
WIDTH = 600

root = tk.Tk()
root.title("Fake BTS")

#termf = tk.Frame(root, height=700, width=600)
#termf.place(height='37', width='120', relx='0.46', rely='0.45')
#wid = termf.winfo_id()
#os.system('xterm -into %d -geometry 400x200 -e /root/.bashrc&' % wid)


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

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

frame = tk.Frame(root, bg= "#80c1ff", bd=5)
frame.place(relx=0.5, rely=0.05, relwidth=0.45, relheight=0.1, anchor='n')

label = tk.Label(frame, text= "Welcome to Fake BTS Detector", bg= "#80c1ff")
label.config(font=("Comic Sans",20, 'bold'))
label.place(rely=0.18, relx='0.16')

lower_frame = tk.Frame(root, bg= '#80c1ff', bd='10')
lower_frame.place(relx=0.5, rely=0.17, relwidth=0.35, relheight=0.08, anchor='n')

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

def run():
	subprocess.call('./grgsm.sh', shell=True)

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



label = tk.Label(lower_frame, text= "Click here to run the scanner", bg= "#80c1ff")
label.config(font=("Comic Sans",12, 'bold'))
label.place(rely=0.22, relx='0.05')

frame_1 = tk.Frame(root, bg= '#80c1ff', bd='10')
frame_1.place(relx=0.5, rely=0.27, relwidth=0.24, relheight=0.06, anchor='n')

label = tk.Label(frame_1, text= "Choose your desired scan", bg= "#80c1ff")
label.config(font=("Comic Sans",12, 'bold'))
label.place(rely=0.03, relx='0.07')

def click():
	#tkinter.messagebox.showinfo("Quick Scan", "Your scan was initiated just now. Please wait to see results")
	#tkinter.messagebox.showinfo("Deep Scan", "Your scan was initiated just now. Please wait to see results")
	root = tk.Tk()
	root.title("Quick Scan")

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

	canvas = tk.Canvas(root, height=350, width=280, bg= "#3498DB")
	canvas.pack()
	
	#tkinter.messagebox.showinfo("Custom Scan", "Please select the tests you want to conduct.")
	
	framez = tk.Frame(canvas, bg= '#80c1ff', bd='10')
	framez.place(relx=0.00, rely=0.00, relwidth=1.0, relheight=1.0)

	label = tk.Label(framez, text= "Scans conducted are:", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.03, relx='0.09')

	label = tk.Label(framez, text= "1. Database Comparison", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.13, relx='0.11')

	
	def clickz():
		tkinter.messagebox.showinfo("Quick Scan", "Your scan was initiated just now. Please wait to see results.")
		subprocess.call('./quickscan.sh', shell=True)
		root.destroy()

	buttonz = tk.Button(framez, text= "Okay", bg= "#DCDCDC", fg= "black", command= clickz)
	buttonz.place(height='37', width='105', relx='0.29', rely='0.73')

	root.mainloop()

button1 = tk.Button(root, text= "Quick Scan", bg= "#80c1ff", fg= "black", command= click)
button1.config(font=("Comic Sans",11,'bold'))
button1.place(height='37', width='105', relx='0.26', rely='0.40')

#btnMenu2 = tk.Menubutton(root, text='Tests Conducted', bg='#80c1ff')
#contentMenu = tk.Menu(btnMenu2)
#btnMenu2.config(menu=contentMenu)
#btnMenu2.place(height='37',width='130', relx='0.25', rely='0.47')

#btnList = ['Database Comparison']
#for btn in btnList:
	#contentMenu.add_command(label=btn)


def click1():
	#tkinter.messagebox.showinfo("Deep Scan", "Your scan was initiated just now. Please wait to see results")
	root = tk.Tk()
	root.title("Deep Scan")

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

	canvas = tk.Canvas(root, height=350, width=280, bg= "#3498DB")
	canvas.pack()
	
	#tkinter.messagebox.showinfo("Custom Scan", "Please select the tests you want to conduct.")
	
	framey = tk.Frame(canvas, bg= '#80c1ff', bd='10')
	framey.place(relx=0.00, rely=0.00, relwidth=1.0, relheight=1.0)

	label = tk.Label(framey, text= "Scans conducted are:", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.03, relx='0.12')

	label = tk.Label(framey, text= "1. Database Comparison", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.13, relx='0.09')

	label = tk.Label(framey, text= "2. Conflicting ARFCNs", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.23, relx='0.09')

	label = tk.Label(framey, text= "3. Conflicting Cell IDs", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.33, relx='0.09')

	label = tk.Label(framey, text= "4. Lonesome Location ID", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.43, relx='0.09')

	label = tk.Label(framey, text= "5. Empty Neighbour List", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.53, relx='0.09')

	label = tk.Label(framey, text= "6. Missing IMSI", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.63, relx='0.09')

	def clicky():
		tkinter.messagebox.showinfo("Deep Scan", "Your scan was initiated just now. Please wait to see results.")
		root.destroy()

	buttony = tk.Button(framey, text= "Okay", bg= "#DCDCDC", fg= "black", command= clicky)
	buttony.place(height='37', width='105', relx='0.29', rely='0.73')

	root.mainloop()


button2 = tk.Button(root, text= "Deep Scan", bg= "#80c1ff", fg= "black", command= click1)
button2.config(font=("Comic Sans",11,'bold'))
button2.place(height='37', width='105', relx='0.66', rely='0.40')

#btnMenu1 = tk.Menubutton(root, text='Tests Conducted', bg='#80c1ff')
#contentMenu = tk.Menu(btnMenu1)
#btnMenu1.config(menu=contentMenu)
#btnMenu1.place(height='37',width='130', relx='0.65', rely='0.47')



#btnList = ['Database Comparison', 'Conflicting ARFCNs', 'Conflicting Cell IDs', 'Lonesome Location ID', 'Empty Neighbour List', 'Missing IMSI']
#for btn in btnList:
	#contentMenu.add_command(label=btn)

def click2():
	root = tk.Tk()
	root.title("Custom Scan")

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

	canvas = tk.Canvas(root, height=350, width=280, bg= "#3498DB")
	canvas.pack()
	
	#tkinter.messagebox.showinfo("Custom Scan", "Please select the tests you want to conduct.")
	
	framex = tk.Frame(canvas, bg= '#80c1ff', bd='10')
	framex.place(relx=0.00, rely=0.00, relwidth=1.0, relheight=1.0)

	label = tk.Label(framex, text= "Select your desired scans", bg= "#80c1ff")
	label.config(font=("Comic Sans",12))
	label.place(rely=0.03, relx='0.03')

	var1 = tk.IntVar()
	self1 = tk.Checkbutton(framex, text="Test 1: Database Comparison", variable=var1, anchor='w')
	self1.place(height='27',width='250', relx='0.02', rely='0.15')

	var2 = tk.IntVar()
	self2 = tk.Checkbutton(framex, text="Test 2: Conflicting ARFCNs", variable=var2, anchor='w')
	self2.place(height='27',width='250', relx='0.02', rely='0.25')

	var3 = tk.IntVar()
	self3 = tk.Checkbutton(framex, text="Test 3: Conflicting Cell IDs", variable=var3, anchor='w')
	self3.place(height='27',width='250', relx='0.02', rely='0.35')

	var4 = tk.IntVar()
	self4 = tk.Checkbutton(framex, text="Test 4: Lonesome Location ID", variable=var4, anchor='w')
	self4.place(height='27',width='250', relx='0.02', rely='0.45')

	var5 = tk.IntVar()
	self5 = tk.Checkbutton(framex, text="Test 5: Empty Neighbour List", variable=var5, anchor='w')
	self5.place(height='27',width='250', relx='0.02', rely='0.55')

	var6 = tk.IntVar()
	self6 = tk.Checkbutton(framex, text="Test 6: Missing IMSI", variable=var6, anchor='w')
	self6.place(height='27',width='250', relx='0.02', rely='0.65')

	def clickx():
		tkinter.messagebox.showinfo("Custom Scan", "Your scan was initiated just now. Please wait to see results.")
		root.destroy()

	buttonx = tk.Button(framex, text= "Okay", bg= "#80c1ff", fg= "black", command= clickx)
	buttonx.place(height='37', width='105', relx='0.29', rely='0.80')

	root.mainloop()
	


button2 = tk.Button(root, text= "Custom Scan", bg= "#80c1ff", fg= "black", command= click2)
button2.config(font=("Comic Sans",11,'bold'))
button2.place(height='37', width='120', relx='0.46', rely='0.40')

def click3():
	tkinter.messagebox.showinfo("Details of Tests", "The details of the tests are: \n \n 1. Test 1: Scan that ARFCN (frequencies), Country Code (MCC), Network Code (MNC), Location and Cell Identity (LAI & CI).\n \n 2. Test 2: Scan that two entries have same ARFCN. \n \n 3. Test 3: Scan that two same ARFCNs have different LAI/CI. \n \n 4. Test 4: Scan that whether one LAI has only one CI. \n \n 5. Test 5: Scan whether neighbour list is empty.\n \n 6. Test 6: Scan whether the IMSI/TMSI field is empty.")

button3 = tk.Button(root, text= "Click Here for Details of Tests", bg= "#80c1ff", fg= "black", command= click3)
button3.place(height='37', width='235', relx='0.415', rely='0.55')

root.mainloop()
Now few of the codes have already been added and a few more are to be added for the operational commands for buttons. The idea is, whenever a button is pressed, it runs either a python command or a shell script on the terminal. I want an instance, where the terminal output can be displayed on the Tkinter window.
Please help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  function in new window (tkinter) Dale22 2 88 Yesterday, 08:24 PM
Last Post: Larz60+
  Scrollable big image in a window (TKinter) Prospekteur 3 256 Sep-14-2020, 03:06 AM
Last Post: Larz60+
  Run more than one window together with tkinter SmukasPlays 1 252 Aug-24-2020, 05:00 PM
Last Post: Larz60+
  Adding an image to a tkinter window djwilson0495 2 753 Aug-23-2020, 11:07 AM
Last Post: ebolisa
  [Tkinter] calling a new window from a tkinter window neuroprogrammer 2 339 Jul-28-2020, 10:59 PM
Last Post: deanhystad
  [Tkinter] Logs and terminal in Tkinter Prezess 1 1,065 Jul-26-2020, 09:49 PM
Last Post: Larz60+
  [Tkinter] Problems to display Web Scraping values in Tkinter Lucas_Ribeiro 0 322 May-07-2020, 12:36 AM
Last Post: Lucas_Ribeiro
  Tkinter: multitab window WizardMitMagi 3 529 Apr-29-2020, 02:40 PM
Last Post: deanhystad
  tkinter.TclError: bad window path name kenwatts275 3 1,605 Apr-26-2020, 08:16 PM
Last Post: kenwatts275
  Using Tkinter widgets on child window chewy1418 8 1,577 Feb-27-2020, 10:34 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020