0
from tkinter import *
class MainBattle(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
global canvas
self.parent.title('Python')
self.pack(fill = BOTH, expand = 1)
canvas = Canvas(self)
self.Label_My = Label(self, text = 'MyObject')
self.Label_My.place(x = 470, y = 35)
canvas.pack(fill = BOTH, expand = 1)
canvas.update()
def aa(self):
self.Label_My['text'] = 'HisObject'
def Change():
Label_My['text'] = 'HisObject'
root = Tk()
ex = MainBattle(root)
root.geometry('700x500')
전역 메소드를 사용해야합니까? 클래스 내부의 레이블을 무시하고 가능한 경우 클래스 외부의 텍스트를 변경합니다.tkinter 캔버스의 텍스트를 클래스 외부로 변경하십시오.
전역 메소드를 사용하는 것보다 편리합니다. 하지만 둘 다 도와 줘서 :) – Montague27