Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何设置Tkinter小部件的像素大小?_Python_Python 3.x_Tkinter - Fatal编程技术网

Python 如何设置Tkinter小部件的像素大小?

Python 如何设置Tkinter小部件的像素大小?,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,每次我必须用Python设计GUI时,我的目标总是PyQt5(Qt Designer 5),因为在我看来,它比Tkinter容易,但现在我有一个任务,必须使用Tkinter 我想在Tkinter中实现的GUI如下: qtdesigner5中的GUI 这是我为Tkinter GUI设计所做的一段代码: from tkinter import Tk,Text from tkinter import ttk class MiApp(ttk.Frame): def __init__(self

每次我必须用Python设计GUI时,我的目标总是PyQt5(Qt Designer 5),因为在我看来,它比Tkinter容易,但现在我有一个任务,必须使用Tkinter

我想在Tkinter中实现的GUI如下:

qtdesigner5中的GUI

这是我为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中的GUI

如何将这些宽度值设置为像素


非常感谢您的关注。

在我不知道的情况下,在创建帧后定义位置内的宽度和高度()允许按像素放置:

    def __init__(self,main_window):
    super().__init__(main_window)
    self.promDaily = []
    self.guidepromDaily = []
    self.datos = {}
    self.csv = " "
    self.minmax = " "
    self.botonCSV = ttk.Button(main_window,text="Escoger CSV",
         command=self.ChooseCSVFile)
    self.botonCSV.place(x=9,y=16,width=91)
    self.pathCSV = ttk.Entry(main_window,state="disable")
    self.pathCSV.place(x=120,y=17,width=351)
    self.labelAbsc = ttk.Label(main_window,text="Abscisa:")
    self.labelAbsc.place(x=9,y=52,width=47)
    self.labelOrden = ttk.Label(main_window,text="Ordenada:")
    self.labelOrden.place(x=120,y=52,width=55)
    self.labelPromD = ttk.Label(main_window,text="Promedio diario:")
    self.labelPromD.place(x=245,y=52,width=95)
    self.comboBAbsc = ttk.Combobox(main_window,state="readonly")
    self.comboBAbsc.place(x=9,y=78,width=91)
    self.comboBOrden = ttk.Combobox(main_window,state="readonly")
    self.comboBOrden.place(x=120, y=78, width=91)
    self.botonCalc = ttk.Button(main_window,text="Calcular", 
        command=self.PromedioDiario)
    self.botonCalc.place(x=245,y=78,width=75)
    self.posibilidadCalc = ttk.Entry(main_window,state="readonly")
    self.posibilidadCalc.place(x=245,y=114,width=211)
    self.botonGraph = ttk.Button(main_window,text="Graficar",
        command=self.GraphCSV)
    self.botonGraph.place(x=62,y=201,width=75)
    self.textMaxMin = Text(main_window,state="disabled")
    self.textMaxMin.place(x=245,y=147, width=211, height=131)
Tkinter中所需的GUI设计


我个人推荐我的项目

tkinter designer在VB6中实现了一个附加组件,您可以在VB6中设计GUI(拖放、调整大小、对齐、颜色、键绑定等),然后此附加组件生成完整的代码框架。您将要做的是在事件方法中添加逻辑代码,如在VB中编码


PS:您可以安装vb6的nano版本。

为什么需要以像素为单位设置宽度?在字符中使用宽度有什么问题?使用字符宽度可以很容易地获得所需的外观。使用
grid
可能比使用
place
要容易得多,这样你就不必做大量的数学运算。我需要设置GUI数据从Qt Designer的坐标和尺寸(以像素为单位)中获取的像素bc宽度,我需要设计尽可能冷静,所以我使用Qt Designer作为指南来节省时间,因为我认为Tkinter默认也使用像素(我错了,哈哈)。每个库都有小部件几何体的默认大小,所以Tkinter按钮的默认宽度可能与Qt不同。