이 글에서는 주로 Python tkinter 모듈의 세 가지 클래스 상속 방법을 소개합니다. 세 가지 상속 방법의 구현 방법과 관련 주의 사항을 예제 형식으로 분석합니다. 도움이 필요한 친구들이 참고할 수 있습니다.
이 글에서는 Python에 대해 설명합니다. 예제가 포함된 tkinter 모듈 클래스 상속의 세 가지 방법. 참고할 수 있도록 모든 사람과 공유하세요. 자세한 내용은 다음과 같습니다.
tkinter 클래스 상속에는 세 가지 방법이 있습니다.
이러한 상속의 작업 방법에 주의하세요
1. 객체 상속
1. tk.Frame을 상위 항목으로 확산:
지침:
self.rootframe = tk .Frame(상위)<code>self.rootframe = tk.Frame(parent)<br>tk.Label(self.rootframe)
import tkinter as tk class MyApp(object): def __init__(self, parent): self.rootframe = tk.Frame(parent) self.rootframe.pack() self.setupUI() def setupUI(self): tk.Label(self.rootframe, text='标签').pack() if __name__ == '__main__': root = tk.Tk() MyApp(root) # 注意这句 root.mainloop()
2.直接使用root
说明:
self.root = parent<br>tk.Label(self.root)
import tkinter as tk class MyApp(object): def __init__(self, parent, **kwargs): self.root = parent self.root.config(**kwargs) self.setupUI() def setupUI(self): tk.Label(self.root, text = '标签').pack() if __name__ == '__main__': root = tk.Tk() app = test(root) root.mainloop()
二、继承 tk.Tk
import tkinter as tk class MyApp(tk.Tk): def __init__(self): super().__init__() self.setupUI() def setupUI(self): tk.Label(self, text='标签').pack() if __name__ == '__main__': MyApp().mainloop()
三、继承 tk.Frame
分两种情况
1.有parent
import tkinter as tk class MyApp(tk.Frame): def __init__(self, parent=None): super().__init__(parent) self.pack() self.setupUI() def setupUI(self): tk.Label(self, text='标签').pack() if __name__ == '__main__': MyApp(tk.Tk()).mainloop() #MyApp().mainloop() # 也可以这样
注意: self.pack()
tk.Label(self.rootframe)
import tkinter as tk class MyApp(tk.Frame): def __init__(self): super().__init__() self.pack() self.setupUI() def setupUI(self): tk.Label(self, text='标签').pack() if __name__ == '__main__': MyApp().mainloop()
2. 루트를 직접 사용
self.root = parent🎜tk.Label( self.root)
🎜🎜🎜🎜rrreee🎜🎜🎜 2. tk를 상속합니다. .Yes parent🎜🎜🎜🎜🎜rrreee🎜참고: self.pack()
🎜🎜🎜2. 부모 없음🎜🎜🎜🎜🎜rrreee위 내용은 tkinter 모듈의 클래스에 대한 세 가지 상속 방법의 Python 공유 예의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Arraysinpython, 특히 비밀 복구를위한 ArecrucialInscientificcomputing.1) theaRearedFornumericalOperations, DataAnalysis 및 MachinELearning.2) Numpy'SimplementationIncensuressuressurations thanpythonlists.3) arraysenablequick

Pyenv, Venv 및 Anaconda를 사용하여 다양한 Python 버전을 관리 할 수 있습니다. 1) PYENV를 사용하여 여러 Python 버전을 관리합니다. Pyenv를 설치하고 글로벌 및 로컬 버전을 설정하십시오. 2) VENV를 사용하여 프로젝트 종속성을 분리하기 위해 가상 환경을 만듭니다. 3) Anaconda를 사용하여 데이터 과학 프로젝트에서 Python 버전을 관리하십시오. 4) 시스템 수준의 작업을 위해 시스템 파이썬을 유지하십시오. 이러한 도구와 전략을 통해 다양한 버전의 Python을 효과적으로 관리하여 프로젝트의 원활한 실행을 보장 할 수 있습니다.

Numpyarrayshaveseveraladvantagesstandardpythonarrays : 1) thearemuchfasterduetoc 기반 간증, 2) thearemorememory-refficient, 특히 withlargedatasets 및 3) wepferoptizedformationsformationstaticaloperations, 만들기, 만들기

어레이의 균질성이 성능에 미치는 영향은 이중입니다. 1) 균질성은 컴파일러가 메모리 액세스를 최적화하고 성능을 향상시킬 수 있습니다. 2) 그러나 유형 다양성을 제한하여 비 효율성으로 이어질 수 있습니다. 요컨대, 올바른 데이터 구조를 선택하는 것이 중요합니다.

tocraftexecutablepythonscripts, 다음과 같은 비스트 프랙티스를 따르십시오 : 1) 1) addashebangline (#!/usr/bin/envpython3) tomakethescriptexecutable.2) setpermissionswithchmod xyour_script.py.3) organtionewithlarstringanduseifname == "__"

numpyarraysarebetterfornumericaloperations 및 multi-dimensionaldata, mumemer-efficientArrays

numpyarraysarebetterforheavynumericalcomputing, whilearraymoduleisiMoresuily-sportainedprojectswithsimpledatatypes.1) numpyarraysofferversatively 및 formanceforgedatasets 및 complexoperations.2) Thearraymoduleisweighit 및 ep

ctypesallowscreatingandmanipulatingC-stylearraysinPython.1)UsectypestointerfacewithClibrariesforperformance.2)CreateC-stylearraysfornumericalcomputations.3)PassarraystoCfunctionsforefficientoperations.However,becautiousofmemorymanagement,performanceo


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기
