会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132367个问题
Python 全系列/第二阶段:Python 深入与提高/模块 1756楼

tkinter *
tkinter.filedialog *  tkinter.colorchooser * tkinter.filedialog *

Application(Frame):

    (master=):
        ().(master)  .master = master
        .textpad = .pack()
        .createWidget()

    ():
        menubar = Menu(root)

        menuFile = Menu(menubar)
        menuEdit = Menu(menubar)
        menuHelp = Menu(menubar)

        menubar.add_cascade(==menuFile)
        menubar.add_cascade(==menuEdit)
        menubar.add_cascade(==menuHelp)

        menuFile.add_command(===.test)
        menuFile.add_command(===.openfile)
        menuFile.add_command(===.savefile)

        menuFile.add_separator()  menuFile.add_command(===.test)

        root[] = menubar

        .textpad = Text(root==)
        .textpad.pack()

        .contextMenu = Menu(root)
        .contextMenu.add_command(==.openAskColor)

        root.bind(.createContextMenu)

    ():
        (askopenfilename(=)=) f:  .textpad.insert(INSERTf.read())
            .filename = f.name

    ():
        (.filename) f:
            c = .textpad.get(END)
            f.write(c)

    ():
        ():
        s1 = askcolor(==)
        root.config(=s1[])

    (event):
        .contextMenu.post(event.x_rootevent.y_root)


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

C:\Users\微软\AppData\Local\Programs\Python\Python37\python.exe C:/Users/微软/pycharm_execrise/pythonProject/GUI/note.py

Exception in Tkinter callback

Traceback (most recent call last):

  File "C:\Users\微软\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__

    return self.func(*args)

  File "C:/Users/微软/pycharm_execrise/pythonProject/GUI/note.py", line 61, in openfile

    self.textpad.insert(INSERT, f.read())

  File "C:\Users\微软\AppData\Local\Programs\Python\Python37\lib\codecs.py", line 322, in decode

    (result, consumed) = self._buffer_decode(data, self.errors, final)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 0: invalid start byte


Process finished with exit code 0


Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1757楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1758楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1759楼

from tkinter import *


class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master = master
        self.pack()

        self.createWight()

    def createWight(self):
        btnTEXT = (("MC", "M+", "M-", "MR"),
                   ("C", "±", "/", "*"),
                   (7,8,9,"-"),
                   (4,5,6,"+"),
                   (0,1,2,"="),
                   (0,"."))
        Entry(self).grid(row=0,column=0, columnspan=4,pady=10)
        for rindex,r in enumerate(btnTEXT):
            for cindex,c in enumerate(r):
                if c == "=":
                    Button(self,text=c,width=2).grid(row=1+rindex,column=cindex, rowspan=2,sticky=NSEW)
                elif c == "0":
                    Button(self,text=c,width=2).grid(row=1+rindex,column=cindex, columnspan=2, sticky=NSEW)
                elif c == ".":
                    Button(self,text=c,width=2).grid(row=1+rindex,column=cindex+1, sticky=NSEW)
                else:
                    Button(self,text=c,width=2).grid(row=1+rindex,column=cindex,sticky=NSEW)



if __name__ == '__main__':
    root = Tk()
    root.title("计算器")
    root.geometry("300x300+200+300")
    app = Application(master=root)
    root.mainloop()

老师,和您的一样,0为啥没有跨列

121ef5b2129d5061242c87b7009e7f1.png

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

pygame
SCREEN_WIDTH=SCREEN_HIGHT=BG_COLOR=pygame.Color()
MainGame():
    window=():
        ():
        pygame.display.init()
        MainGame.widow=pygame.display.set_mode([SCREEN_WIDTHSCREEN_HIGHT])
        pygame.display.set_caption()
        :
            MainGame.window.fill(BG_COLOR)
            pygame.display.update()
    ():
        Tank():
    ():
        ():
        ():
        ():
        MyTank():
    ():
        EnemyTank(Tank):
    ():
        ().()
Bullet():
    ():
        ():
        ():
        Wall():
    ():
        ():
        Explode():
    ():
        ():
        Music():
    ():
        ():
        __name__==:
    MainGame().startGame()

C:\Users\86137\PycharmProjects\mypro01\venv\Scripts\python.exe C:/Users/86137/PycharmProjects/mypro01/tanke01.py

pygame 2.0.1 (SDL 2.0.14, Python 3.9.2)

Hello from the pygame community. https://www.pygame.org/contribute.html

Traceback (most recent call last):

  File "C:\Users\86137\PycharmProjects\mypro01\tanke01.py", line 101, in <module>

    MainGame().startGame()

  File "C:\Users\86137\PycharmProjects\mypro01\tanke01.py", line 48, in startGame

    MainGame.window.fill(BG_COLOR)

AttributeError: 'NoneType' object has no attribute 'fill'


Process finished with exit code 1

运行的时候为什么是fill错误呀、、、

Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 1768楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 1769楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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