会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133690个问题
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 931楼
Python 全系列/第二阶段:Python 深入与提高/模块 932楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 935楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 936楼

老师看看哪里出了问题

from tkinter import *
from tkinter.filedialog import *
from tkinter.colorchooser import *


class Application(Frame):
    def __init__(self, master=None):
        super().__init__(master)  # super()代表父类的定义,而不是父类的对象
        self.master = master
        self.textpad = None  # textpad表示Text文本框对象
        self.pack()
        self.createWidget()

    def createWidget(self):
        # 创建主菜单栏
        menubar = Menu(root)
        # 创建子菜单
        menuFile = Menu(menubar)
        menuEdit = Menu(menubar)
        menuHelp = Menu(menubar)
        # 将子菜单加入到主菜单栏中
        menubar.add_cascade(label="文件(F)", menu=menuFile)
        menubar.add_cascade(label="编辑(E)", menu=menuEdit)
        menubar.add_cascade(label="帮助(H)", menu=menuHelp)
        # 添加菜单项
        menuFile.add_command(label="新建", accelerator="ctrl+n", command=self.test)
        menuFile.add_command(label="打开", accelerator="ctrl+o", command=self.test)
        menuFile.add_command(label="保存", accelerator="ctrl+s", command=self.test)
        menuFile.add_separator()  # 添加分割线
        menuFile.add_command(label="退出", accelerator="ctrl+q", command=self.test)
        # 将主菜单栏加到根窗口
        root["menu"] = menubar
        # 文本编辑区
        self.textpad = Text(root, width=50, heigth=30)
        self.textpad.pack()
        # 创建上下菜单
        self.contextMenu = Menu(root)
        self.contextMenu.add_command(label="背景颜色", command=self.test)
        # 右键绑定事件
        root.bind("<Button-3>", self.createContextMenu)

    def test(self):
        pass

    def createContextMenu(self, event):
        #  菜单在鼠标右键单击的坐标处显示
        self.contextMenu.post(event.x_root, event.y_root)


if __name__ == '__main__':
    root = Tk()
    root.geometry("450x300+200+300")
    root.title("百战程序员的简易记事本")
    app = Application(master=root)
    root.mainloop()

image.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 937楼

f25ef247eb781f24a05fc87142e93fd.png

为什么不用在init后面的括号里面写images,下面不是对images初始化了吗

Python 全系列/第二阶段:Python 深入与提高/坦克大战 938楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 939楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 942楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 943楼

tkinter *
tkinter messagebox
webbrowser

Application(Frame): (master=): ().(master) .master = master .pack() .createWidget()

    (): .w1 = Text(root===).w1.pack().w1.insert().w1.insert()Button(==.insertText).pack(=) Button(==.returnText).pack(=)Button(==.addImage).pack(=)Button(==.addWidget).pack(=)():.w1.insert(INSERT).w1.insert(END).w1.insert()():(.w1.get())(+.w1.get(END)) ():
        .photo = PhotoImage(=)
        .w1.image_create(END=.photo)

    ():
        b1 = Button(.w1=).w1.window_create(INSERT=b1)

    ():
        .w1.delete(END) .w1.insert(INSERT) .w1.tag_add() .w1.tag_config(==) .w1.tag_add() .w1.tag_config(=).w1.tag_bind(.webshow)():
        webbrowser.open()

__name__ == :
    root = Tk()
    root.geometry=()
    app = Application(=root)
    root.mainloop()

报错

Traceback (most recent call last):

  File "D:/Users/MM/PycharmProjects/gui/my06.py", line 61, in <module>

    app = Application(master=root)

  File "D:/Users/MM/PycharmProjects/gui/my06.py", line 12, in __init__

    self.createWidget()

  File "D:/Users/MM/PycharmProjects/gui/my06.py", line 23, in createWidget

    Button(self, text="添加图片", command=self.addImage).pack(sied="left")#要在下方定义方法

  File "C:\Program Files\Python37\lib\tkinter\__init__.py", line 2143, in pack_configure

    + self._options(cnf, kw))

_tkinter.TclError: bad option "-sied": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side



Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 944楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637