[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Python GUI with Tkinter – 2 – Organizing your Layout
by
Tags:
Comments
47 responses to “Python GUI with Tkinter – 2 – Organizing your Layout”
-
if you wanted the color of the button itself you could type another optional argument called "bg"
-
The buttons weren't colored for some reason.
-
Thanks !!
-
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. 🙂
-
thanks man!
-
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. -
Why not just bottomFrame = Frame(root).pack(side=BOTTOM) ?
btn1 = Button(bottomFrame, text="okay", fg="red").pack() -
Python GUI with Tkinte
-
the colors won't work
-
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()
-
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 ?
-
How can i move the button by x and y cordinations?
good video! -
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 requiredProcess finished with exit code 1
-
So can I import my python code and add tkinter code to make a gui or how do I do that
-
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.
-
fg colors won't work on mac
-
no wix i dont need a god damn website now let me watch this video
-
its like add your money in your part of your public storage and again we have to lock(pack) it
-
Very good introduction and demo.
-
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
-
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
-
Thanks a lot @thenewboston, this video series is really helpful for first time users. It's super helpful. Thanks again.
-
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 -
very nice.
-
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 -
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
-
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?
-
Hi there,
Is there any difference in doing:top_frame = Frame(root).pack()
or
top_frame = Frame(root)
top_frame.pack()just curious 🙂
-
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()
-
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
-
i can relate python with java like:
Tk = Frame
Frame = Panel
pack = add -
If you dropkick the computer, will you make a video of it?
-
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?
-
The word button does not sound like a real word anymore
-
what ide are you using
-
thank you so much!
-
#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 optionalbutton1.pack(side=LEFT,fill=X)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
button4.pack(side=BOTTOM)root.mainloop()
-
Bucky, you're awesome dude!
-
Is there an easier way to create variable names? Something like for x in range(4): buttonx = ….
-
Project is due Friday, i'm on your second video. I hope I've chosen the best Tkinter tutorial for this binge-watch!
-
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
-
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.
-
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
-
What do the 'fg' next to the colours stand for? isn't it bg?
-
I think fg and bg are not supported on mac !
-
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?? -
thank you, best tutorial about GUI
Leave a Reply