会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132655个问题

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编程(隐藏) 1771楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1772楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 1774楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 1775楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1777楼

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 深入与提高/游戏开发-坦克大战 1778楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 1779楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1781楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1783楼

#coding=utf-8   checkbutton可以多选
from tkinter import *
from tkinter import messagebox
class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.pack()
        self.creatWidget()
    def creatWidget(self):
        self.v1=StringVar()
        self.v2=StringVar()
        self.r1=Checkbutton(self,text="敲代码",onvalue=1,offvalue=0,variable=self.v1)
        self.r2=Checkbutton(self,text="看视频",onvalue=1,offvalue=0,variable=self.v2)
        self.r1.pack()
        self.r2.pack()
        Button(self,text="确定",command=self.confirm).pack(side="left")
    def confirm(self):
        if self.v1.get()==1:
            messagebox.showinfo("测试","是更喜欢敲代码哟!")
        if self.v2.get()==1:
            messagebox.showinfo("测试","是更喜欢看视频哟!")
if __name__=='__main__':
    root=Tk()
    root.geometry("200x300+100+260")
    app=Application(master=root)
    root.mainloop()

老师,帮忙看看我的代码哪里出问题了,一运行就是两个都选上了,然后只选一个没有反应。还有就是不太理解pack后面设置的side到底定义的是谁的位置,那个单选里面我写女性那里side=right是图1,写side=left是图2,到底是相对于谁right和left呀image.pngimage.png我的确定没有加side

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

课程分类

百战程序员微信公众号

百战程序员微信小程序

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