對于在外的游子,每逢佳節倍思親。而對于996ICU的苦逼程序猿們,最期待的莫過于各種節假日能把自己丟在床上好好休息一下了。這幾天各公司都陸續開始發中秋禮品了。朋友圈各種秀高顏值的月餅,所以今天我也提前給大家送去一份中秋的美味月餅吧!
python的turtle庫,最早還是在小甲魚的【零基礎入門學習Python】中接觸的,好久沒用了有些生疏,帶大家一起回顧下模塊的使用吧。
如果你是想認真學習這個庫,推薦去官網仔細學習 https://docs.python.org/3.7/library/turtle.html
但如果你只是跟我一樣玩票性質的,那么你簡單看看就好。我幫你整理了一些常用的方法:
就以上這些完全夠你強勢裝13了…
練習畫月餅
話不多說,先來一波!
然后,還沒開團呢,先送一血了…為什么pycharm會告警呢?
但是使用又是正常的好奇怪,網上搜了一下解決辦法。從import turtle進入源碼,把142行開始的all注釋掉,手動引用下turtle的所有方法即可。
# __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions + # _tg_utilities + ['Terminator']) # + _math_functions) __all__ = ['ScrolledCanvas', 'TurtleScreen', 'Screen', 'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D', 'back', 'backward', 'begin_fill', 'begin_poly', 'bk', 'addshape', 'bgcolor', 'bgpic', 'bye', 'clearscreen', 'colormode', 'delay', 'exitonclick', 'getcanvas', 'getshapes', 'listen', 'mainloop', 'mode', 'numinput', 'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer', 'register_shape', 'resetscreen', 'screensize', 'setup', 'Terminator', 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles', 'update', 'window_height', 'window_width', 'write_docstringdict', 'done', 'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd', 'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease', 'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'right', 'reset', 'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt', 'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']
問題解決了,開始寫吧:
看看效果:

總結
以上所述是小編給大家介紹的使用Python為中秋節繪制一塊美味的月餅,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
