Reputation: 423
as for the question mentioned, i cant find any code which can fixed the gui window and positions of all the labels, buttons etc..
import tkinter
import tkinter.messagebox
class Menu:
def __init__(self):
self.main = tkinter.Tk(height = 200, width = 400)
self.position = tkinter.Label(self.main, text = '123',\
bg = 'Purple',\
height = 2, width = 8)
self.position.place(height=50, width= 100)
self.position.pack()
tkinter.mainloop()
gui = Menu()
for this, i can only do the sizing of the label, not the position and the size of the main window. it gives this error
Traceback (most recent call last):
File "C:\Python33\Saves\Label position.py", line 18, in <module>
gui = Menu()
File "C:\Python33\Saves\Label position.py", line 7, in __init__
self.main = tkinter.Tk(height = 200, width = 400)
TypeError: __init__() got an unexpected keyword argument 'height'
Upvotes: 0
Views: 9440
Reputation: 41
You can use the resizable function.
root = Tk()
root.title('TITLE')
root.resizable(0, 0)
Upvotes: 0
Reputation: 11
The right method to do this is to write this line after your window declaration :
{yourwindow}.resizable(width = False, height = False)
Source : https://www.youtube.com/watch?v=SVW0ofsBKCU
Upvotes: 1
Reputation: 6330
Use the minsize
and maxsize
methods to set the size of the window. The following code will make a fixed size window. Of course, you can skip one of them to give your user the option to resize the window in any one direction.
top = tkinter.Tk()
top.minsize(width=300, height=300)
top.maxsize(width=300, height=300)
Upvotes: 1
Reputation: 20679
It looks like you cannot set the width and height of the Tk element in the constructor. However, you can use the geometry
method:
self.main = tkinter.Tk()
self.main.geometry("400x200")
Upvotes: 3