每次我必须在 Python 中设计 GUI 时,我的首选总是 PyQt5(Qt Designer 5),因为在我看来,它比 Tkinter 更容易,但现在我有一个任务并且必须使用 Tkinter。
我想在 Tkinter 中实现的 GUI 是这样的:
Qt Designer 5 中的图形用户界面
这是我为 Tkinter GUI 设计所做的一段代码:
from tkinter import Tk,Text
from tkinter import ttk
class MiApp(ttk.Frame):
def __init__(self,main_window):
super().__init__(main_window)
self.promDaily = []
self.datos = {}
self.csv = " "
self.botonCSV = ttk.Button(main_window,text="Escoger CSV",width=91,command=self.ChooseCSVFile)
self.botonCSV.place(x=9,y=16)
self.pathCSV = ttk.Entry(main_window,width=351,state="disable")
self.pathCSV.place(x=120,y=17)
self.labelAbsc = ttk.Label(main_window,text="Abscisa:",width=47)
self.labelAbsc.place(x=9,y=52)
self.labelOrden = ttk.Label(main_window,text="Ordenada:",width=55)
self.labelOrden.place(x=120,y=52)
self.labelPromD = ttk.Label(main_window,text="Promedio diario:",width=79)
self.labelPromD.place(x=245,y=52)
self.comboBAbsc = ttk.Combobox(main_window,width=91)
self.comboBAbsc.place(x=9,y=78)
self.comboBOrden = ttk.Combobox(main_window, width=91)
self.comboBOrden.place(x=120, y=78)
self.botonCalc = ttk.Button(main_window,text="Calcular",width=75)
self.botonCalc.place(x=245,y=78)
self.posibilidadCalc = ttk.Entry(main_window,width=211)
self.posibilidadCalc.place(x=245,y=114)
self.botonGraph = ttk.Button(main_window,width=75)
self.botonGraph.place(x=62,y=201)
self.textMaxMin = Text(main_window,width=211,height=131)
self.textMaxMin.place(x=245,y=147)
(...)
root = Tk()
root.config(width=480,height=337)
mainW = ttk.Frame(root,width=480,height=337)
mainW.pack()
root.resizable(0,0)
app = MiApp(mainW)
app.mainloop()
现在,我的 Tkinter GUI 看起来像这样:
Tkinter 中的图形用户界面
如何将这些宽度值设置为像素?
感谢您的关注。