Issue
So if i try to resize my Window with the same button back and forth just the one on the bottom will work but it wont go back to '384x470' as if the Window wasnt '500x500'
def sizeWindow():
if root.geometry('500x500'):
root.geometry('384x470')
else:
root.geometry('500x500')
buttonWinSize.configure(text="<<")```
Solution
You seem to misunderstand several things here. Tkinter has relatively cool feature that allows you to use some methods for different things. Either you get or you set with the same method. To get you leave the interface empty (e.g. root.geometry()
) or you set with the required argument (e.g. root.geometry('500x500+0+0')
). You should be aware that you get the current value(s) in the same format as you set them.
Therefore you retrieve a geometry string by root.geometry()
and this has the form of width x height +x +y.
However, not every time this feature is the right tool to achieve the overall goal. In your case you want to check for the width and height. Tkinter provides another feature for exactly this task. It lets you ask for the width and height via winfo_width()
and winfo_height()
.
In addition you should know that every function in python needs to return something and if nothing is specified None
is returned by this function. Since you use the setter variant of root.geometry('500x500')
you receive None
and None
equals to False
in python, therefore your else
block will always be executed instead of your if
block.
Suggested change:
def sizeWindow():
if root.winfo_width() == 500 and root.winfo_height() == 500:
root.geometry('384x470')
else:
root.geometry('500x500')
Answered By - Thingamabobs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.