Pythonda grafik oynada ob’ektni uchirish kuchirish va nusha qilishga misollar.
from graphics import *
win = GraphWin("Окнодляграфики", 400, 400)
obj = Polygon(Point(30, 10), Point(30, 50), Point(20, 30), Point(15, 30),
Point(7, 7)) obj.setOutline("blue")
102
obj.setWidth(2) obj.setFill("cyan") obj.draw(win) win.getMouse() obj.undraw() win.getMouse() obj.draw(win) obj.move(100, 100) win.getMouse() shape = obj.clone()
shape.move(-100, -100) shape.draw(win) win.getMouse() win.close()
GRAFIK OYNADA MATNNI YARATISH UCHUN PYTHONDA BUYRUQ QO’LLANILADI
MATN OB'EKTI=Text(MATNNI JOYLASHUV NUQTASI KOORDINATALARI, “MATN”)
msg = Text(Point(50, 100), “Hello World!”)
(50, 100) koordinatali nuqtada ekranda Hello World! satr ajratidi
matn o’lchovini o’zgartirish uchun quyidagi buyruq qo'llaniladi: matnli ob'ekt.setSize(matn o'lchovi)
msg.setSize(12)
setTextColor(rang) msg.setTextColor(“black”) uslub orqali matn rangi ozgaradi grafik ob’ektda matnni quyidagi uslub orqali o’zgartirish mumkin:setText(“Matn”) msg.setText(“Boshqa rang”)
matn stili quyidagi protsedura orqali setStyle(stil) msg.setStyle(“bold”) o’zgartiriladi.
Normal stil matn stilini oddiyga, bold yarim qalin stilga, italic ursivga, yani egma
103
shriftga o’zgartiradi. Bold italic esa matn stilini yarim qalinlashgan kursivga o’zgartiradi.
Pythonda matnni grafik oynada ko’rsatuvchi dasturga misol.
from graphics import *
win = GraphWin("Окнодляграфики", 400, 400)
obj = Polygon(Point(10, 10), Point(300, 50), Point(200, 300), Point(150, 150),
Point(70, 70)) obj.setOutline("blue") obj.setWidth(5) obj.setFill("cyan") obj.draw(win) win.getMouse() obj.undraw()
msg = Text(Point(200, 200), "EKRANDAN FIGURA UCHIRILDI")
msg.setSize(12) msg.setTextColor("black") msg.setStyle("bold italic") msg.draw(win) win.getMouse() win.close()
4.Dasturlshga doir misollar.
Do'stlaringiz bilan baham: |