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

struct
math
threading
time
sys
multiprocessing
multiprocessing Process


read_csv(filename):

    start_time = time.time()

    sem
    sem = threading.Semaphore()

    file
    file = (filename, )
    (% file.read().decode())

    encoded_triangles = file.read()
    triangles = .from_bytes(encoded_triangles, )

    manager = multiprocessing.Manager()
    return_tot = manager.dict()
    totals = []

    return_coord = manager.dict()
    coords = []


    index (, ):
        p = Process(=thread_compute, =(index, triangles, return_tot, return_coord))
        totals.append(p)
        coords.append(p)
        p.start()
    
    index (, ):
        p.join()

    total_area = index (, ):
        total_area += return_tot[index]

    min_box = find_box(return_coord[], return_coord[], return_coord[], return_coord[])

    end_time = time.time()
    total_time = end_time - start_time

    triangles, total_area, min_box, total_time

thread_compute(index, triangles, return_tot, return_coord):
    total_area = min_max = []

    start = (index * triangles / )
    (triangles / )  > triangles - :
        end = triangles
    :
        end = start + (triangles / )

    triangle (start, end):
        
        sem.acquire()
        = [file.read(), file.read(), file.read()]
        p1 = [file.read(), file.read(), file.read()]
        p2 = [file.read(), file.read(), file.read()]
        p3 = [file.read(), file.read(), file.read()]
        = file.read()
        sem.release()

        p1, p2, p3 = process_coord(p1, p2, p3)
        tri_area = compute(p1, p2, p3)

        total_area += tri_area

        temp = []
        i (,):
            temp.append(([p1[i], p2[i], p3[i]]))
        i (,):
            temp.append(([p1[i], p2[i], p3[i]]))

        triangle == start:
            min_max = temp
        :
            i (,):
                temp[i] < min_max[i]:
                    min_max[i] = temp[i]
            i (,):
                temp[i] > min_max[i]:
                    min_max[i] = temp[i]

    return_coord[index] = min_max
    return_tot[index] = total_area

process_coord(p1, p2, p3):
    p1 = convert_values(p1)
    p2 = convert_values(p2)
    p3 = convert_values(p3)
    p1, p2, p3

convert_values(point):
    [struct.unpack(, point[])[],
            struct.unpack(, point[])[],
            struct.unpack(, point[])[]]

compute(p1, p2, p3):
    a = math.sqrt((p2[] - p1[]) ** + (p2[] - p1[]) ** + (p2[] - p1[]) ** )
    b = math.sqrt((p3[] - p1[]) ** + (p3[] - p1[]) ** + (p3[] - p1[]) ** )
    c = math.sqrt((p3[] - p2[]) ** + (p3[] - p2[]) ** + (p3[] - p2[]) ** )
    p = (a + b + c) / area = math.sqrt(p * (p - a) * (p - b) * (p - c))
    area

find_box(min_max1, min_max2, min_max3, min_max4):

    = []
    min_max = min_max1

    i (,):
        min_max2[i] < min_max[i]:
            min_max[i] = min_max2[i]
    i (,):
        min_max2[i] > min_max[i]:
            min_max[i] = min_max2[i]
    i (,):
        min_max3[i] < min_max[i]:
            min_max[i] = min_max3[i]
    i (,):
        min_max3[i] > min_max[i]:
            min_max[i] = min_max3[i]
    i (,):
        min_max4[i] < min_max[i]:
            min_max[i] = min_max4[i]
    i (,):
        min_max4[i] > min_max[i]:
            min_max[i] = min_max4[i]
    
    
    line1 = math.sqrt((min_max[] - min_max[]) ** )
    line2 = math.sqrt((min_max[] - min_max[]) ** )
    line3 = math.sqrt((min_max[] - min_max[]) ** )
    box = % (line1, line2, line3)
    box

show_output(triangles, total_area, min_box, ):
    (% triangles)
    (% total_area)
    (% min_box)
    (% )

__name__ == :
    (sys.argv) < :
        ()
    filename = (sys.argv[])
    triangles, total_area, min_box, total_time = read_csv(filename)
    show_output(triangles, total_area, min_box, total_time)


image.png

老师,您帮我看看,这个报这个错误,我应该在哪里输入文件名字

Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 1982楼

屏幕截图 2024-07-02 014642.png

老师您好,我这边按照视频操作一直到创建虚拟环境什么的都没问题,在新版VS Code中选择好解释器后打开终端输入“pip install pygame==2.3.0”后报错,然后我切换到命令提示符,先workon tank_game_env激活,然后输入“pip install pygame==2.3.0”按回车之后报错,请问这要怎么解决呢?

Python 全系列/第二阶段:Python 深入与提高/坦克大战 1983楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 1985楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 1986楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1989楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 1990楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1992楼
Python 全系列/第二阶段:Python 深入与提高/模块 1993楼

'''测试一个经典的GUI程序的写法,使用面向对象的方式'''
from tkinter import *
from tkinter import  messagebox


class Application(Frame):
    '''一个经典的GUI程序的类的写法'''
    def __init__(self,master=None):
        super().__init__(master)#super()代表的是父类的定义,而不是父类对象
        self.master=master
        self.pack()

        self.creatWidget()  # 通过这种方式进行调用

    def creatWidget(self):
        '''创建新组建'''
        self.label01=Label(self,text="百战程序员",width=10,height=2,
                           bg="black",fg="white")
        self.label01.pack()
        self.label02=Label(self,text="百战程序员",width=10,height=2,
                           bg="pink",fg='white',font=('楷体',30))
        self.label02.pack()

        #显示图像
        global photo
        photo = PhotoImage(file="cyx.gif")#创建一个图片对象

        self.label03=Label(self,image=photo)#利用image参数对这个标签进行赋值
        self.label03.pack()

        self.label04=Label(self,text="sd\nsdf\n",
                           borderwidth=1,relief="solid",justify="right")
        self.label04.pack()

        self.but01=Button(self,text="quit",command=root.destroy())
    def songhua(self):
        messagebox.showinfo("pythonGUI/florwer","99")  #第一个是框框的标题,第二个是框框里的内容

if __name__=="__main__":
    root=Tk()

    app=Application(master=root)
    root.geometry('200x100+300+300')
    root.mainloop()

老师,我想加一个退出的button,但是这个一直报错,请问是为什么

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

from tkinter import *
from tkinter import messagebox
class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.pack()
        self.createWidget()
    def createWidget(self):
        #创建一个标签(组件)
        self.label01=Label(self,text="百战程序员",width=10,height=2
                           ,bg="black",fg="white")
        self.label01.pack()
        self.label02=Label(self,text="姬昊余",width=15,height=1,
                           bg="red",fg="blue",font=("宋体","30"))
        self.label02.pack()

        #显示图像
        global photo #因为photo为局部变量 必须声明为全局变量,否则执行完语句,图像自动销毁,不会显示
        photo=PhotoImage(file="image/123.gif")#先创建一个photo容器
        self.label03=Label(self,image=photo)
        self.label03.pack()

        #显示多行文本
        self.label04=Label(self,text="姬昊余\n吕倩倩",borderwidth="10",relief="groove"
                           ,justify="left")
        self.label04.pack()
        #justify文本对齐方式  relief边框样式  borderwidth边框宽度

        #创建一个送花按钮
        self.btn01=Button(root)
        self.btn01["text"]="点击送花"
        self.btn01["command"]=self.songhua
        #songhua后边加括号就成了自动执行 不加括号为触发事件
        self.btn01.pack()
    def songhua(self):
        messagebox.showinfo("送花","送你一朵小花花")

root=Tk()
root.geometry("400x200+200+300")
root.title("一个经典的GUI")
app=Application(root)
root.mainloop()

老师 你说 self.btn=Button(root)和self.btn=Button(self)的区别是 这两个按钮在不同的父组件里,那这两个父组件有什么区别,代码底下不是 app=Application(root) 这个app为什么是个父组件


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

课程分类

百战程序员微信公众号

百战程序员微信小程序

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