簡體   English   中英

面向對象編程中的 tkinter

[英]tkinter in object-oriented programming

我正在做 OOP 代碼,我有一些問題,我已經搜索了互聯網,據說我做得對。 但它給了我一個錯誤並且不執行我。

我有這個:

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()

我想要的是從 function 將 tkinter Label插入視口。 但它在崇高的文本中給了我這個錯誤:

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]

您需要使用 4 個空格或制表符來修復縮進。 您不能在它們之間互換,否則它將不起作用。 我不知道為什么,但就是這樣。 我建議將它們移回開始,然后使用制表符直到縮進正確。 擺脫縮進的空間。 確保按照@Bryan Oakley 的建議搜索(復制和粘貼)您得到的確切錯誤代碼(即“TabError:縮進中制表符和空格的不一致使用”)進行研究。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM