Python Forum
thinker button gui place next to each other
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
thinker button gui place next to each other
#10
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:
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 :-)
Reply


Messages In This Thread
RE: thinker button gui place next to each other - by wuf - Jul-04-2019, 07:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Place QT Window in the middle AlphaInc 10 2,041 Aug-03-2023, 05:40 PM
Last Post: Axel_Erfurt
  [Tkinter] how to make label or button not visible with the place method? nowayj63 2 2,636 Jan-03-2023, 06:29 PM
Last Post: Yoriz
  Label.Place did not work? ATARI_LIVE 15 5,055 Sep-18-2020, 04:22 PM
Last Post: ATARI_LIVE
  [Tkinter] How to place scroll bar correctly scratchmyhead 1 3,896 May-18-2020, 04:17 PM
Last Post: scratchmyhead
  How to use place holders in tkinter sqlite scratchmyhead 1 1,781 May-12-2020, 06:13 PM
Last Post: Larz60+
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,947 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

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