If you’re using TK or QT to edit a canvas interface, you might want to use absolute positioning, even percentage positioning, for things like window size drags and drags, and that would be pretty bad, so personally, I’ve always made the window undrag-and-resize.
Anonymous user: “how to set?” .
Ok, let’s satisfy this netizen and help him solve the problem.
Ps: The inner play is really full ~
PyQt5
For QT programs, although there is a QT Designer that can achieve graphical coding and achieve the canvas interface shown in the end, I personally feel that it is not useful, maybe I am too stupid, or prefer to write in code:
#! /usr/bin/env python
# _*_ Coding: UTF-8 _*_
from PyQt5 import QtWidgets
if __name__ == '__main__':
app = QtWidgets.QApplication([])
windows = QtWidgets.QWidget()
windows.setWindowTitle('Medusa MQT')
windows.setMinimumWidth(400)
windows.setMaximumWidth(400)
windows.setMinimumHeight(400)
windows.setMaximumHeight(400)
windows.show()
app.exec_()
Copy the code
In lines 9 through 12, we use configuration Max and min values to limit window sizes, while QT displays without a mouse.As you can see from the GIF above, moving the mouse over the edge of the screen does not show a double arrow icon, which means you cannot change the size of the head of the bed.
Tkinter
TK is slightly different, although there is a double arrow icon near the edge of the canvas, drag and drop has no effect due to the properties set.
#! /usr/bin/env python
# _*_ Coding: UTF-8 _*_
import tkinter as tk
if __name__ == '__main__':
window = tk.Tk()
window.title('Medusa MTK')
window.minsize(400.400)
window.maxsize(400.400)
window.mainloop()
Copy the code
The maximum and minimum width and height values are set in lines 8 and 9, so this limits the maximum and minimum size of window drags.In the example, drag and drop was tested only once, but in fact, drag and drop from inside to outside did not work, and achieved the desired effect.
Afterword.
As a matter of fact, canvas components developed are usually positioned more with relative values. If the size is not limited, the components may be blocked and a large blank area may be left. There are still some minor problems in aesthetics, of course, this does not affect the use of functions. If you’re a small program like me and want to make it even better, check out this Python Tkinter example of using background images and transparent fonts and PyQT5 to set background images.
The purpose of immutable width and height is also to show the background,
There is no problem with incomplete background coverage.