小编S. *_*kar的帖子

如何在整个代码中使用__init__方法中定义的变量?

在这里,我正在尝试使用python和tkinter以及OOP构建文本编辑器.但问题是我无法在代码中使用预定义变量.

from tkinter import *
from tkinter import Tk, Menu, Label, PhotoImage, StringVar, IntVar
from PIL import Image, ImageTk

PROGRAM_NAME = 'PyEdit'


class TextEditor:

    def __init__(self, root):

        self.root = root
        self.root.tk.call('wm', 'iconphoto', self.root._w, photo)
        self.root.title(PROGRAM_NAME)
        self.root.geometry('350x280')
        self.init_gui()

        self.title_image = Image.open('Text-Edit-icon.png')
        self.photo = ImageTk.PhotoImage(title_image)
        self.help = Image.open('icons/helpicon.png')
        self.new_icon = PhotoImage(file='icons/new_file.gif')
        self.save_icon = PhotoImage(file='icons/save.gif')
        self.cut_icon = PhotoImage(file='icons/cut.gif')
        self.copy_icon = PhotoImage(file='icons/copy.gif')
        self.undo_icon = PhotoImage(file='icons/undo.gif')
        self.open_icon = PhotoImage(file='icons/open_file.gif')
        self.about_icon = PhotoImage(file='icons/about.gif')
        self.redo_icon = PhotoImage(file='icons/redo.gif')
        self.find_icon = PhotoImage(file='icons/onfind.gif')
        self.help_icon = ImageTk.PhotoImage(help)
        self.paste_icon = PhotoImage(file='icons/paste.gif')

    def …
Run Code Online (Sandbox Code Playgroud)

python tkinter tkinter-menu

2
推荐指数
1
解决办法
59
查看次数

标签 统计

python ×1

tkinter ×1

tkinter-menu ×1