会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132413个问题
JAVA 全系列/第一阶段:JAVA 快速入门/控制语句、方法、递归算法 11522楼

https://hub.docker.com/

老师打不开网址怎么办a

Python 全系列/第六阶段:生产环境部署与协同开发/docker容器扩展 11524楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/智能电话本项目实战 11525楼
Python 全系列/第十一阶段:重量级Web框架-Django/Django初级 11526楼

from tkinter import *
# from tkinter import messagebox
import webbrowser
class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)   #super代表父类的定义,而不是父类的对象
        self.master=master
        self.pack()
        self.createWidget()

    def createWidget(self):
        self.w1=Text(root,width=40,height=12,bg="gray")
        # 宽度20个字母(10个汉字),高度一个行高
        self.w1.pack()
        self.w1.insert(1.0,"0123456789\nabcdefg")
        self.w1.insert(2.3,"锄禾日当午,汗滴禾下土。谁知盘中餐,粒粒皆辛苦\n")
        Button(self, text="重复插入文本",command=self.insertText).pack(side="left")
        Button(self, text="返回文本",command=self.returnText).pack(side="left")
        Button(self, text="添加图片",command=self.addImage).pack(side="left")
        Button(self, text="添加组件",command=self.addWidget).pack(sode="left")
        Button(self, text="通过tag精确控制文本",command=self.testTag).pack(side="left")

    def insertText(self):
        # Insert索引表示在光标处插入
        self.w1.insert(INSERT,"Gaoqi")
        #End索引号所以表示在最后插入
        self.w1.insert(END,"[sxt]")
        self.w1.insert(1.8, "gaoqi")

    def returnText(self):
        # Indexes(索引)是用来指向Text组件中文本的位置,Text的组件索引也是对应实际字符之间的位置
        # 核心:行号以1开始,列号以0开始
        print(self.w1.get(1.2,1.6))
        print("所有文本内容:\n"+self.w1.get(1.0,END))

    def addImage(self):
        # global photo
        self.photo=PhotoImage(file="imgs/logo1.png")
        self.w1.image_create(END,image=self.photo)

    def addWidget(self):
        b1=Button(self.w1,text="尚学堂")
        # 在text创建组件的命令
        self.w1.window_create(INSERT,window=b1)

    def textTag(self):
        self.w1.delete(1.0,END)
        self.w1.insert(INSERT,"good good good study,day day up\n北京尚学堂\n百战程序员\n希望2020年会心想事成")
        self.w1.tag_add("good", 1.0, 1.9)
        self.w1.tag_config("good", background="yellow", foreground="red")
        self.w1.tag_add("baidu",4.0,4.2)
        self.w1.tag_config("baidu",underline=True)
        self.w1.tag_bind("baidu","<Button-1>",self.webshow)
    def webshow(self,event):
        webbrowser.open("http://www.baidu.com")

if __name__ == "__main__":
    root = Tk()
    root.geometry("400x130+200+300")
    #root.title("一个经典的GUI程序类的测试")
    app=Application(master=root)
    root.mainloop()

Traceback (most recent call last):

  File "D:\AAAAAAAAApython\gui\my05.py", line 62, in <module>

    app=Application(master=root)

  File "D:\AAAAAAAAApython\gui\my05.py", line 10, in __init__

    self.createWidget()

  File "D:\AAAAAAAAApython\gui\my05.py", line 21, in createWidget

    Button(self, text="添加组件",command=self.addWidget).pack(sode="left")

  File "D:\lib\tkinter\__init__.py", line 2425, in pack_configure

    self.tk.call(

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

老师我为什么报这么错啊

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 11527楼
WEB前端全系列/第二十阶段:Git版本控制器/Git版本控制器 11529楼

图片.png

Python 全系列/第一阶段:Python入门/函数和内存分析 11531楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图高级 11532楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 11533楼

import turtle

a=input("请输入一个x:")
b=input("请输入一个y:")
c=input("请输入一个width:")
d=input("请输入一个height:")

class MyRectangle:

    def __init__(self,x,y,width,height):


        self.x=x
        self.y=y
        self.width=width
        self.height=height

        if self.x=="":
            self.x=0

        if self.x!="":
            self.x=float(x)

        if self.y=="":
            self.y=0

        if self.y!="":
            self.y=float(y)

        if self.width == "":
            self.width = 100

        if self.width!="":
            self.width=float(width)

        if self.height == "":
            self.height = 100

        if self.height!="":
            self.height=float(height)

    def getArea(self):
        return self.width*self.height

    def getPerimeter(self):
        return 2*(self.height+self.width)

    def draw(self):
        turtle.color("red")
        turtle.penup()
        turtle.goto(self.x,self.y)
        turtle.pendown()
        turtle.right(90)
        turtle.forward(self.width)
        turtle.right(90)
        turtle.forward(self.height)
        turtle.right(90)
        turtle.forward(self.width)
        turtle.right(90)
        turtle.forward(self.height)
        turtle.done



m1=MyRectangle(a,b,c,d)
print(m1.getArea())
print(m1.getPerimeter())
m1.draw()

老师,为什么我在调用draw方法的之后海龟作图不显示?

Python 全系列/第一阶段:Python入门/面向对象 11535楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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