我经常看到Tkinter应用程序在构造函数中初始化Menu小部件tearoff=0.
import tkinter as tk
root = tk.Tk()
menubar = tk.Menu(root)
filemenu = tk.Menu(menubar, tearoff=0)
Run Code Online (Sandbox Code Playgroud)
effbot.org的文档Menu指定默认值为tearoff1,但它没有解释该值的用途.
tearoff=
Default value is 1. (tearOff/TearOff)
tearoffcommand=
No default value. (tearOffCommand/TearOffCommand)
Run Code Online (Sandbox Code Playgroud)
什么是tearoff初始化Tkinter的属性时,做Menu小部件?
在这里,我正在尝试使用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)