简体   繁体   English

面向对象编程中的 tkinter

[英]tkinter in object-oriented programming

I am doing OOP code and I have some problem, I have searched the internet and supposedly I am doing it right.我正在做 OOP 代码,我有一些问题,我已经搜索了互联网,据说我做得对。 But it gives me an error and does not execute me.但它给了我一个错误并且不执行我。

I have this:我有这个:

from tkinter import *
from tkinter import ttk
import pymysql
from tkinter import messagebox as MessageBox
from tkinter import scrolledtext as st

class Aplicacion:
    def __init__(self):
        self.ventana1 = Tk()
        self.ventana1.title("Login")
        self.ventana1.geometry("400x400")
        self.imagenLogo = PhotoImage(file="logo2.png")
        self.divLogo = Label(self.ventana1, image=self.imagenLogo)
        self.divLogo.place(x=93, y=0)
        self.x_ventana = self.ventana1.winfo_screenwidth() // 2 - 300 // 2
        self.y_ventana = self.ventana1.winfo_screenheight() // 2 - 300 // 2
        self.posicion = str(300) + "x" + str(300) + "+" + str(self.x_ventana) + "+" + str(self.y_ventana)
        self.ventana1.geometry(self.posicion)
        self.ventana1.resizable(0,0)
        self.formulario()
        self.ventana1.mainloop()

    def formulario(self):
        ### Formulario de Entrada ###
        self.label1 = ttk.Label(text="Usuario:").place(x=50, y=110)


Ventana = Aplicacion()

What I want is to insert a tkinter Label into the viewport from a function.我想要的是从 function 将 tkinter Label插入视口。 But it gives me this error in sublime text:但它在崇高的文本中给了我这个错误:

File "/Users/tomas/Downloads/DonMovil/objetos.py", line 29
    self.label1 = ttk.Label(text="Usuario:").place(x=50, y=110)
TabError: inconsistent use of tabs and spaces in indentation
[Finished in 47ms with exit code 1]
[cmd: ['python3', '-u', '/Users/tomas/Downloads/DonMovil/objetos.py']]
[dir: /Users/tomas/Downloads/DonMovil]
[path: /Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin]

You need to fix indentation by using either 4 spaces or a tab.您需要使用 4 个空格或制表符来修复缩进。 You can't interchange between them or it won't work.您不能在它们之间互换,否则它将不起作用。 I don't know why but that is the way it is.我不知道为什么,但就是这样。 I recommend shift tabbing them back to start and then using tab until the indentation is right.我建议将它们移回开始,然后使用制表符直到缩进正确。 Get rid of spaces for indentations too.摆脱缩进的空间。 Make sure to research by searching (copying and pasting) the exact error code you got (IE "TabError: inconsistent use of tabs and spaces in indentation") as @Bryan Oakley suggested.确保按照@Bryan Oakley 的建议搜索(复制和粘贴)您得到的确切错误代码(即“TabError:缩进中制表符和空格的不一致使用”)进行研究。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM