English 中文(简体)
如何使文本成为字典中的反对
原标题:how to make text a class object in python

这是我的整个法典:

from Graphics import *
import random
import time
from Myro import *
pt = Point(100,50)
pink = makeColor(200,100,150)
black = makeColor(0,0,0)
red = makeColor(255, 0, 0)
green = makeColor(0, 255, 0)
blue = makeColor(0, 0, 255)
purple = makeColor(255, 0, 255)
orange = makeColor(255, 153, 0)

win = Window("name", 1000, 500)
p1 = Point(0,0)
p2 = Point(200, 300)
p3 = Point(200,0)
d3 = Dot(p3)
p4 = Point(400, 300)
d4 = Dot(p4)
p5 = Point(400, 0)
p6 = Point(600, 300)
p7 = Point(600, 0)
p8 = Point(800,300)
p9 = Point(800,0)
p0 = Point(1000, 300)

win.setBackground(pink)
class Classes(object):
    WIDTH = 200
    HEIGHT = 300

    five = Rectangle(p9, p0)
    five.setOutline(black)
    five.setFill(orange)
    five.draw(win)
    four = Rectangle(p7, p8)
    four.setOutline(black)
    four.setFill(purple)
    four.draw(win)
    three = Rectangle(p5, p6)
    three.setOutline(black)
    three.setFill(blue)
    three.draw(win)
    two = Rectangle(p3, p4)
    two.setOutline(black)
    two.setFill(green)
    two.draw(win)
    one = Rectangle(p1, p2)
    one.setOutline(black)
    one.setFill(red)
    one.draw(win)

       def __init__(self,p,win):
        def numClasses(self):
            num = ask("How many classes do you have? Enter a number 1-5")
            int(num)
            if num == 1:


        def askOne(self):
            one = ask   

   class classOne(Classes):
    def __init__(self, win):
        Classes.__init__(self, win)
        self.appearance.setFill(red)
        self.appearance.setOutline(black)   

        #self.append(win)
class classTwo(Classes):
    def __init__(self, win):
        Classes.__init__(self,win)
        self.appearance= Text(Point(100, 10), "Class 1")
        self.appearance.fontSize = 10
        self.appearance.setFill(black)
        self.appearance.draw(win)
        win.flip()
class classThree(Classes):
    def __init__(self, win):
        Classes.__init__(self,  win)
        self.appearance.setFill(blue)
        self.appearance.setOutline(black)
class classFour(Classes):
    def __init__(self,  win):
        Classes.__init__(self,  win)
        self.appearance.setFill(orange)
        self.appearance.setOutline(black)
class classFive(Classes):
    def __init__(self,  win):
        Classes.__init__(self, win)
        self.appearance.setFill(purple)
        self.appearance.setOutline(black)

t = time.strftime("%Y-%m-%d")
ti = Text(Point(win.getWidth()/2, 475), t)
ti.fontSize = 26
ti.setFill(black)
ti.draw(win)

title = Text(Point(win.getWidth()/2, 440), "Schedule for the week of:")
title.setFill(black)
title.fontSize = 20
title.draw(win)

classes = []

另一回事 窗口是使用i m这一版本的一种功能,即由于其预先界定而可以加以界定。 它只是打开了一条单独的窗口(1,000×500)粉碎机,供你提取物品。 i 仅需要知道,在进入一个班子时,如何找到案文。 它致力于修补/点/沙皮,但不是案文。 i 不知道原因。

问题回答

第一,尽管你描述了这些班子(你告诉我们哪类学校应该看好,以及它应该如何工作),但你从未实际创造过!

第二,如果你抽取案文,那么盒子就会压倒案文,而你则 t。

第三,你在座的课堂确实非常坏。 它希望你重新努力完成学校的日历,为每个学校阶段单独开设一个“灰色”课程——掌握数据,用硬线连接数据。 相反,你应该有一个通用的“灰色”课,然后在每学期单独开课。

ie, instead of

a = FirstPeriod()
b = SecondPeriod()
c = ThirdPeriod()

你们应当思考一下

a = Period("First", blue, black)
b = Period("Second", orange, black)
c = Period("Third", purple, black)

为什么?

  • it makes what you are trying to accomplish more immediately obvious
  • it reduces the amount of code (and thus the amount of debugging)
  • it makes it much easier to make later changes

Edit: 这里是一些经过重整的法典——我没有安装卡利科,因此没有经过测试,但我希望它给你这个想法:

import Myro
from Graphics import Window, Point, Dot, Text, makeColor
import random
import time

Black  = makeColor(0,0,0)
White  = makeColor(255,255,255)
Red    = makeColor(255, 0, 0)
Green  = makeColor(0, 255, 0)
Blue   = makeColor(0, 0, 255)
Purple = makeColor(255, 0, 255)
Pink   = makeColor(200,100,150)
Orange = makeColor(255, 153, 0)
Grey   = makeColor(165, 165, 165)

Monday, Tuesday, Wednesday, Thursday, Friday = range(5)

class Period(object):
    def __init__(self,
        className="<spare>",
        textColor=Black,
        bgColor=White,
        borderColor=Black,
        schedule=None
    ):
        self.name     = className
        self.text     = textColor
        self.bg       = bgColor
        self.border   = borderColor
        self.schedule = schedule or []

    def draw(self, win, rows, columns):
        for day,(start,length) in self.schedule:
            # draw background box
            box = Rectangle(
                Point(columns[day],  rows[start]),
                Point(columns[day+1],rows[start+length])
            )
            box.setFill(self.bg)
            box.setOutline(self.border)
            box.draw(win)
            # draw class name
            label = Text(Point(columns[day]+10,rows[start]+40), self.name)
            label.fontSize = 9
            label.setFill(self.text)
            label.draw(win)

def Week(object):
    def __init__(self, label, periods=None):
        self.label   = label
        self.periods = periods or []

    def draw(self, win, left, top, width, height):
        # how much room to reserve at the top
        label_space = 40

        # draw label at top
        label = Text(Point(Point(left+0.5*width, top+0.5*label_space)), self.label)
        label.fontSize = 20
        label.setFill(Black)
        label.draw(win)

        # figure out the grid for displaying the calendar boxes
        days = 5
        columns = [left + width*n/days for n in range(days+1)]
        periods = 5
        rows = [top + label_space + (height-label_space)*n/periods for n in range(periods+1)]

        # draw class periods based on the grid
        for p in self.periods:
            p.draw(win, rows, columns)

def main():
    win = Window("My window", 1000, 500)
    win.setBackground(Pink)

    week = Week("14 May 2012",
        [
            Period("Math",    bgColor=Red,   schedule=[(Monday,(0,1)), (Wednesday,(0,1)), (Friday,(0,1))]),
            Period("Geology", bgColor=Grey,  schedule=[(Monday,(1,1)), (Tuesday,(0,1)), (Thursday,(0,1))]),
            Period("English", bgColor=Blue,  schedule=[(Tuesday,(1,1)), (Wednesday,(3,1)), (Thursday,(1,1))]),
            Period("LUNCH",   bgColor=White, schedule=[(Monday,(2,1)), (Tuesday,(2,1)), (Wednesday,(2,1)), (Thursday,(2,1)), (Friday,(2,1))]),
            Period("Gym",     bgColor=Orange, schedule=[(Tuesday,(3,2)), (Thursday,(3,2))])
        ]
    )
    week.draw(win, 10, 10, 980, 290)
    # have to do something here to prevent closing immediately?

if __name__=="__main__":
    main()

Your code should write text to the screen if you create an instance of the class. So if you add this below your classes,

c2 = classTwo(win)

它应当将物体提上舱。 窗口两处。

此外,我对前面的胜诉部分感到错。 这在法典中是不恰当的。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签