尝试在tkinter中进行简单的移动:
import tkinter as tk
class GameApp(object):
"""
An object for the game window.
Attributes:
master: Main window tied to the application
canvas: The canvas of this window
"""
def __init__(self, master):
"""
Initialize the window and canvas of the game.
"""
self.master = master
self.master.title = "Game"
self.master.geometry('{}x{}'.format(500, 500))
self.canvas = tk.Canvas(self.master)
self.canvas.pack(side="top", fill="both", expand=True)
self.start_game()
#----------------------------------------------#
def start_game(self):
"""
Actual loading of the game.
"""
player = Player(self)
#----------------------------------------------#
#----------------------------------------------#
class Player(object):
"""
The player of the game. …Run Code Online (Sandbox Code Playgroud) Tkinter忙着闲逛,想知道是否有一种方法可以创建一个具有可变数量拐角的多边形?我正在尝试编写一个程序,其中涉及用户输入一定数量的坐标,然后在画布上绘制具有这些点边缘的多边形。由于我不知道用户将输入的值的数量,因此不可能为每种可能性编写代码,那么这真的可能吗?
canvas.create_polygon(x1,y1,x2,y2...xn,yn,fill="black")
Run Code Online (Sandbox Code Playgroud)