Python GUI with Tkinter – 2 – Organizing your Layout

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

47 responses to “Python GUI with Tkinter – 2 – Organizing your Layout”

  1. alexandru costin Avatar

    if you wanted the color of the button itself you could type another optional argument called "bg"

  2. Veritox Avatar

    The buttons weren't colored for some reason.

  3. ツ Gamesys Avatar

    Man you are amazing! Instead of just simply showing code and giving a tiny bit of shitty explanation you put the effort of showing us an example so we understand better. 🙂

  4. Álvaro B F Avatar

    Is it possible not to use .mainloop()?
    I am using python 3.5 on Windows 10, and my GUI stays on display without the .mainloop() class.

  5. John Walker Avatar

    Why not just bottomFrame = Frame(root).pack(side=BOTTOM) ?
    btn1 = Button(bottomFrame, text="okay", fg="red").pack()

  6. WAGUE BOCAR Avatar

    Python GUI with Tkinte

  7. Teddy James Avatar

    the colors won't work

  8. Ishmeet Bindra Avatar

    If someone is having a trouble in understanding how the framing works run the following code. In this, I have just added few commands to Frame and Pack to add additional padding around the two Frames.

    from tkinter import *

    root = Tk()

    topframe = Frame(root, bd=5, relief = GROOVE)
    topframe.pack(side=TOP,fill=X, padx=2, pady=2)

    bottomframe = Frame(root, bd=5,relief = GROOVE)
    bottomframe.pack(side=BOTTOM,fill=X, padx=2,pady=2)

    button1 = Button(topframe,text = "button 1",bg='white',fg = 'black')
    button2 = Button(topframe,text = "button 2",bg='white',fg = 'black')
    button3 = Button(topframe,text = "button 3",bg='white',fg = 'black')
    button4 = Button(bottomframe,text = "button 4",bg='white',fg = 'red')

    button1.pack(side='left')
    button2.pack(side='left')
    button3.pack(side='left')
    button4.pack()

    root.mainloop()

  9. Tushar Mittal Avatar

    hey i am using python 3.6.1 and typed the same code as in the video but it gives an error – NameError: name 'frame' is not defined. Any suggestions on how to fix this ?

  10. דיויד דינסטון Avatar

    How can i move the button by x and y cordinations?
    good video!

  11. MCDran Avatar

    It won't work for me I normally have Python 3 but what ever

    C:Python27python.exe C:/Users/Mr.Retorofit/PycharmProjects/untitled/bucky.py
    Traceback (most recent call last):
    File "C:/Users/Mr.Retorofit/PycharmProjects/untitled/bucky.py", line 10, in <module>
    button1 = Button(topFrame, "Button 1", fg="Red")
    File "C:Python27liblib-tkTkinter.py", line 2166, in _init_
    Widget.__init__(self, master, 'button', cnf, kw)
    File "C:Python27liblib-tkTkinter.py", line 2085, in _init_
    cnf = _cnfmerge((cnf, kw))
    File "C:Python27liblib-tkTkinter.py", line 116, in _cnfmerge
    cnf.update(c)
    ValueError: dictionary update sequence element #0 has length 1; 2 is required

    Process finished with exit code 1

  12. MCDran Avatar

    So can I import my python code and add tkinter code to make a gui or how do I do that

  13. Dario Komar Avatar

    I had a mental breakdown with WinAPI and C. After all those years, I decided to stop forcing myself to do stuff with C. Seeing this made me smile and gave me hope to code again. Thank you.

  14. Stitch07 Avatar

    fg colors won't work on mac

  15. Cyplex Avatar

    no wix i dont need a god damn website now let me watch this video

  16. Nir Tech Avatar

    its like add your money in your part of your public storage and again we have to lock(pack) it

  17. Mingshuo Ji Avatar

    Very good introduction and demo.

  18. SavoirPourTous Avatar

    So thank you for your lesson, but I have no color on my buttons, one idea, last thing I work on mac with El Capitan

  19. John Mauney Avatar

    tkinter.pack() must have changed because I get a name error if I use bottomFrame.pack(side=BOTTOM), but not if I use bottomFrame.pack(side="bottom")

    Current documentation: https://docs.python.org/3.5/library/tkinter.html#packer-options

  20. Pooja Bhalode Avatar

    Thanks a lot @thenewboston, this video series is really helpful for first time users. It's super helpful. Thanks again.

  21. Anders Turesson Avatar

    I just got Pycharm 2016.3.2 as demo and Python 3.6. I put in the code exactly the same way you did, but I get a Name Error when I try to run it. button1 = button(topFrame, text="Button 1", fg="red")
    NameError: name 'button' is not defined

  22. karl thecoder Avatar

    Hi Bucky, can I pack a frame like this: bottomLeftFrame.pack(side=BOTTOMLEFT )
    cuz I want it in the left corner at the bottom. HOW? XD

  23. Michael Valentino Avatar

    I just watched the first video but can already tell this Playlist is going to be awesome. Finally, someone who knows how to teach stuff at the perfect pace. Thank you

  24. Samarjeet Saluja Avatar

    hey thenewboston. Im running this program on idle on a mac and the colors of the buttons do not show. I should i change this?

  25. Harold W Avatar

    Hi there,
    Is there any difference in doing:

    top_frame = Frame(root).pack()

    or

    top_frame = Frame(root)
    top_frame.pack()

    just curious 🙂

  26. Fufilschmerz SM Avatar

    TypeError: object of type 'Frame' has no len()

    Help pls
    Has found an answer in the web but It seems like I have evrything correct.

    from tkinter import *

    root = Tk()

    topFrame = Frame(root)
    topFrame.pack()
    botFrame = Frame(root)
    botFrame.pack(side=BOTTOM)

    words = Label(root, text='Click any button you like')
    words.pack(topFrame)

    but1 = Button(botFrame, text='red', fg='red')
    but2 = Button(botFrame, text='blue', fg='blue')

    but1.pack(side=LEFT)
    but2.pack(side=RIGHT)

    root.mainloop()

  27. Cool Guy Avatar

    from tkinter import *

    root = Tk()

    topframe = frame(root)
    topframe.pack()

    bottomframe = frame(root)
    bottomframe.pack(side=BOTTOM)

    button1 = Button(topframe, Text="button1", fg="red")
    button2 = Button(topframe, Text="button2", fg="red")
    button3 = Button(topframe, Text="button3", fg="red")
    button4 = Button(bottomframe, Text="button4", fg="red")

    button1.pack()
    button2.pack()
    button3.pack()
    button4.pack()

    root.mainroot()

    buttons don't work

    python 3.5.1

  28. Prabhakar Kevat Avatar

    i can relate python with java like:
    Tk = Frame
    Frame = Panel
    pack = add

  29. Hampton Ford Avatar

    If you dropkick the computer, will you make a video of it?

  30. ColtonVEVO Mix Tapes Avatar

    For me fg="WhateverColorIChoose" Doesn't work. Saying blue,red,yellow and othe colors still doesn't change anything? Btw it's on python 3.5.2 any ideas?

  31. WispsOfLight Avatar

    The word button does not sound like a real word anymore

  32. Travis Sloas Avatar

    what ide are you using

  33. Gerry GUAN Avatar

    thank you so much!

  34. Geek Zone Avatar

    #Code cheat sheet – Like this comment so that everyone can see
    from tkinter import *
    root=Tk()

    topFrame = Frame(root)
    topFrame.pack()
    bottomFrame = Frame(root)
    bottomFrame.pack(side=BOTTOM)

    button1=Button(topFrame, text="Button 1", fg="red") #fg foreground is optional
    button2=Button(topFrame, text="Button 2", fg="blue") #fg is optional
    button3=Button(topFrame, text="Button 3", fg="green") #fg is optional
    button4=Button(bottomFrame, text="Button 4", fg="black") #fg is optional

    button1.pack(side=LEFT,fill=X)
    button2.pack(side=LEFT)
    button3.pack(side=LEFT)
    button4.pack(side=BOTTOM)

    root.mainloop()

  35. dota noob Avatar

    Bucky, you're awesome dude!

  36. Zwerggoldhamster Avatar

    Is there an easier way to create variable names? Something like for x in range(4): buttonx = ….

  37. 1pnoe Avatar

    Project is due Friday, i'm on your second video. I hope I've chosen the best Tkinter tutorial for this binge-watch!

  38. Fuzzytutor FREE online Learning Avatar

    button1 = Button(topFrame, text='Button1', fg='red') i used this for my button and everything worked except for fg='red' the button color did not change and i also tried to do Foreground='red' that didnt work either and this is python 3.5 on a mac

  39. Omar Matos Avatar

    Very clear explanation and very fun. Thank you for sharing. I would like to know if there's a more visual way of working with object-oriented in python. Instead of coding the buttons and positioning, maybe dragging from a toolbox and dropping into a defined windows also done graphically? But anyways I will keep on practicing and visit your sites. Thank you again.

  40. jimmys_popcorn Avatar

    Oh man I love the videos but what a funny way of explaining where the windows would end up on the screen :D!

    Thanks alot <3

  41. Xi Jinping Avatar

    What do the 'fg' next to the colours stand for? isn't it bg?

  42. Scientist Avatar

    I think fg and bg are not supported on mac !

  43. Harold W Avatar

    Hi Guys
    Im on a mac using python 3.5 and the latest pycharm
    My problem is the colours are not changing when i set them in the code
    ie. button2 = Button(topFrame, text="Button2", bg="green") also changing to fg makes no difference any thoughts??

  44. Adi Purnama Avatar

    thank you, best tutorial about GUI

Leave a Reply

Your email address will not be published. Required fields are marked *