Jul-04-2019, 07:48 AM
Hi jacklee26
When using the pack Layout Manager frames are mainly used as invisible containers to group individual widgets in a group. So you can handle the widget group when placing it with the help of a frame like a single widget.
For a try, i have modified your script with several such container frames:
wuf :-)
When using the pack Layout Manager frames are mainly used as invisible containers to group individual widgets in a group. So you can handle the widget group when placing it with the help of a frame like a single widget.
For a try, i have modified your script with several such container frames:
import tkinter as tk import subprocess def clear_text(): result.destroy() def ping(): cmd = ["ping", entry.get(), "-n", "2"] output = subprocess.check_output(cmd) #print (output) #output = subprocess.check_output("ping {} -c 2".format(entry.get()), shell=True) #print under console #print('>', output) #with open('test.txt', 'w') as f: #cls print(output, file=f) # put result in label #result['text'] = output.decode('utf-8') result['text'] = output.decode('big5') # This is the main window my_gui = tk.Tk() entry = tk.StringVar() my_gui.geometry('300x300') my_gui.title("Get output inside GUI") # This is the main frame in the main window. # With the pack properties padx & pady the main_frame gets an 4 pixel border and # the expand causes the frame to be placed at the center of the screen by # expanding the main window of the gui to full screen size. main_frame = tk.Frame(my_gui) main_frame.pack(padx=4, pady=4, expand=True) # This frame is used to contain mainly the entry related widgets and # is placed in the main_frame. entry_frame = tk.Frame(main_frame) entry_frame.pack(pady=4) tk.Label(entry_frame, text="Enter target IP or host as required.",bg = 'red' ).pack(side='top') tk.Entry(entry_frame, textvariable=entry, bg = 'yellow').pack() # This frame is used to contain mainly the control related widgets like buttons and # is placed also in the main_frame button_frame = tk.Frame(main_frame) button_frame.pack(pady=4) tk.Button(button_frame,text="Ping Test", bd=2, command=ping).pack(side='left') tk.Button(button_frame,text="Clear", bd=2, command=clear_text).pack(side='left') # label for ping result # This label widget is also placed in the main_frame result = tk.Label(main_frame, bg='blue', height="20", width="50") result.pack() my_gui.mainloop()Hope you understand what i am trying to explain?
wuf :-)