本文整理汇总了Python中Canvas.pack方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.pack方法的具体用法?Python Canvas.pack怎么用?Python Canvas.pack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.pack方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
class CanvasDemo:
colors = ["pink", "grey", "yellow", "green", "red", "purple", "cyan",
"pink", "grey", "yellow", "green", "red", "purple", "cyan",
"pink", "grey", "yellow", "green", "red", "purple", "cyan"]
layers = 5
root = canvas = groups = None
def __init__(self, root):
self.root = root
# make a frame and a canvas and some buttons
frame = Frame(self.root)
frame.pack(fill=X)
label = Label(frame, text="Canvas test")
label.pack()
self.canvas = Canvas(frame, bg="grey", width=600, height=600)
self.canvas.pack()
cmd = Button(frame, text="Scale", command=self.scale)
cmd.pack()
self.groups = []
for i in range(self.layers):
self.groups.append(Group(self.canvas))
# time the creation of the rectangles
start = time()
self.makeShapes()
print "Took ", time() - start, " seconds to make", self.layers,"layers"
def makeShapes(self):
# make 100 rectangles
for group in range(self.layers):
actual = self.groups[group]
MouseHandler(actual)
for i1 in range(10):
for i2 in range(10):
makeRectangle(self.canvas, actual, i1*40+10+group*20,
i2*40+10+group*5,
35, 35, self.colors[group], 2)
def scale(self):
for group in self.groups:
group.scale(0, 0, 1.1, 1.1)
示例2: len
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
return [[(1 + t[0]) * WIDTH / 2 , (1 - t[1]) * HEIGHT / 2] for t in points]
if __name__ == "__main__":
#check parameters
if len(sys.argv) != 2:
print "pointViewerTemplate.py"
sys.exit(-1)
# create main window
mw = Tk()
# create and position canvas and buttons
cFr = Frame(mw, width=WIDTH, height=HEIGHT, relief="sunken", bd=1)
cFr.pack(side="top")
can = Canvas(cFr, width=WIDTH, height=HEIGHT)
can.pack()
bFr = Frame(mw)
bFr.pack(side="left")
bRotYn = Button(bFr, text="<-", command=rotYn)
bRotYn.pack(side="left")
bRotYp = Button(bFr, text="->", command=rotYp)
bRotYp.pack(side="left")
eFr = Frame(mw)
eFr.pack(side="right")
bExit = Button(eFr, text="Quit", command=(lambda root=mw: quit(root)))
bExit.pack()
modelObj = model.parse(sys.argv[1])
cam.setupCameraForModel(modelObj)
draw()
示例3: return
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
return (beta_gamma,alpha_gamma)
# in this definition is the repaint of the triangle and the decision if is a --
# green or red dot
def clicked_point(event):
canv.delete(ALL)
trian(a,b,c)
x0 = event.x
y0 = event.y
p = complex(x0,y0)
x = faktor(p)
if (( 1>= x[0][0] >=0) and (x[0][1]>=0)):
canv.create_oval(x0-4,y0-4,x0+4,y0+4,fill='green')
else:
if (( 1>= x[1][0] >=0) and (x[1][1]>=0)):
canv.create_oval(x0-4,y0-4,x0+4,y0+4,fill='green')
else:
canv.create_oval(x0-4,y0-4,x0+4,y0+4,fill='red')
root = Tk()
canv = Canvas(root,width=size,height=size)
trian(a,b,c)
canv.bind("<Button-1>",clicked_point)
canv.bind("<B1-Motion>",clicked)
canv.pack()
root.mainloop()
示例4: sched_queerity
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
def sched_queerity():
tk.after(min_queerity_sleep + int(random()*(max_queerity_sleep-min_queerity_sleep)), queerity)
intro()
if os_name == 'posix':
def exiting():
system("xset r on")
atexit.register(exiting)
system("xset r off")
cursor="dot #111111"
else:
cursor=None
tk = Tk()
canvas = Canvas(tk, width=w, height=h, background='black', cursor=cursor)
canvas.pack(fill=BOTH, expand=Y)
center = w/2+h/2*1j
tk.bind("h", help)
tk.bind("i", info)
tk.bind("<Escape>", do_exit)
start()
sched_queerity()
tk.mainloop()
示例5: Plot
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
class Plot(object):
'''
A canvas will be created where the selected values will be plotted as lines, with the best fitting scale.
Initial version by:
Michel Heiniger and Sandra Lang
Latest source code can be found at:
https://github.com/nebelriss/FluidX
'''
def __init__(self, master, frame, sw, sh):
'''
Constructor for the plot area.
'''
# initialization of
self.sw = sw
self.sh = sh
self.frame = frame
# empty value list
self.value_list = []
# canvas area where the value lines and the coordinate system
self.canvas = Canvas(self.frame, bg = "white")
self.canvas.pack(expand = YES, fill = BOTH)
#if the used os is a windows or a mac, they need a factor 1.5 for the y-axis
if os.name == "nt":
self.win_osx_factor = 1.5
elif os.name == "mac":
self.win_osx_factor = 1.5
# if its a linux machine factor is 1
else:
self.win_osx_factor = 1
def createCoordSystem(self):
'''
This creates the coordinate system with a given max value for x,y axis.
'''
# Interval for the numbers
self.xInterval = 2
self.yInterval = 0.2
# delete all canvas with the tag "text"
self.canvas.delete("text")
# draw axis lines
self.canvas.create_line(self.sw-315, self.sh-150, 50, self.sh-150, fill = "black", width = 1)
self.canvas.create_line(70, self.sh-130, 70, 70, fill = "black", width = 1)
# text for Axis
y = 'Y-Axis'
x = 'X-Axis'
# write the text at the right position
self.canvas.create_text(70,40, text= y, tag = "text")
self.canvas.create_text(self.sw-315,self.sh-120, text= x, tag = "text")
# numbers for x and y axis
maximumx = ((self.xMax) + 2) / self.xInterval
maximumy = ((self.yMax) + 1) / self.yInterval
# loop to write the numbers under the axis line and draw the separation lines for the x-axis
for i in range(int(maximumx)):
x = 70 + (i * self.dist_x * self.xInterval)
self.canvas.create_line(x,self.sh-150,x,self.sh-155, width = 2)
self.canvas.create_text(x,self.sh-140, text='%d'% (i * self.xInterval), anchor=N, tag = "text")
# loop to write the numbers under the axis line and draw the separation lines for the x-axis
for i in range (int(maximumy)):
y = self.sh-150-(i * self.dist_y * self.yInterval) * self.win_osx_factor
self.canvas.create_line(70,y,75,y, width = 2)
self.canvas.create_text(45,y, text=str((i * self.yInterval)), anchor=W, tag = "text")
def createline (self, meta, values, idx, sel_idx, colors):
'''
Fist the given values are written in a list with the index number of the listbox and the selected items.
'''
# remove all lines with the tag "plot"
self.canvas.delete("plot")
# overwrite values with the given index with none
try:
self.value_list[idx][1] = None
except IndexError:
print "Index Error - List out of range"
#.........这里部分代码省略.........
示例6: paper
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
def paper(width=400, height=300, colour="white"):
global canvas, tk, paper_w, paper_h
paper_w = width ; paper_h = height
tk = Tk()
canvas = Canvas(tk, width=width, height=height, background=colour)
canvas.pack(fill=BOTH, expand=Y)
示例7: SudokuUI
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
class SudokuUI(Frame):
"""
The Tkinter UI, responsible for drawing the board and accepting user input.
"""
def __init__(self, parent, game):
self.game = game
Frame.__init__(self, parent)
self.parent = parent
self.row, self.col = -1, -1
self.__initUI()
def __initUI(self):
self.parent.title("Sudoku")
self.pack(fill=BOTH)
self.canvas = Canvas(self,
width=WIDTH,
height=HEIGHT)
self.canvas.pack(fill=BOTH, side=TOP)
clear_button = Button(self,
text="Clear answers",
command=self.__clear_answers)
clear_button.pack(fill=BOTH, side=BOTTOM)
self.__draw_grid()
self.__draw_puzzle()
self.canvas.bind("<Button-1>", self.__cell_clicked)
self.canvas.bind("<Key>", self.__key_pressed)
def __draw_grid(self):
"""
Draws grid divided with blue lines into 3x3 squares
"""
for i in xrange(10):
color = "blue" if i % 3 == 0 else "gray"
x0 = MARGIN + i * SIDE
y0 = MARGIN
x1 = MARGIN + i * SIDE
y1 = HEIGHT - MARGIN
self.canvas.create_line(x0, y0, x1, y1, fill=color)
x0 = MARGIN
y0 = MARGIN + i * SIDE
x1 = WIDTH - MARGIN
y1 = MARGIN + i * SIDE
self.canvas.create_line(x0, y0, x1, y1, fill=color)
def __draw_puzzle(self):
self.canvas.delete("numbers")
for i in xrange(9):
for j in xrange(9):
answer = self.game.puzzle[i][j]
if answer != 0:
x = MARGIN + j * SIDE + SIDE / 2
y = MARGIN + i * SIDE + SIDE / 2
original = self.game.start_puzzle[i][j]
color = "black" if answer == original else "sea green"
self.canvas.create_text(
x, y, text=answer, tags="numbers", fill=color
)
def __draw_cursor(self):
self.canvas.delete("cursor")
if self.row >= 0 and self.col >= 0:
x0 = MARGIN + self.col * SIDE + 1
y0 = MARGIN + self.row * SIDE + 1
x1 = MARGIN + (self.col + 1) * SIDE - 1
y1 = MARGIN + (self.row + 1) * SIDE - 1
self.canvas.create_rectangle(
x0, y0, x1, y1,
outline="red", tags="cursor"
)
def __draw_victory(self):
# create a oval (which will be a circle)
x0 = y0 = MARGIN + SIDE * 2
x1 = y1 = MARGIN + SIDE * 7
self.canvas.create_oval(
x0, y0, x1, y1,
tags="victory", fill="dark orange", outline="orange"
)
# create text
x = y = MARGIN + 4 * SIDE + SIDE / 2
self.canvas.create_text(
x, y,
text="You win!", tags="victory",
fill="white", font=("Arial", 32)
)
def __cell_clicked(self, event):
if self.game.game_over:
return
x, y = event.x, event.y
if (MARGIN < x < WIDTH - MARGIN and MARGIN < y < HEIGHT - MARGIN):
self.canvas.focus_set()
# get row and col numbers from x,y coordinates
#.........这里部分代码省略.........
示例8: __init__
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import pack [as 别名]
class woyDraw:
def __init__(self,ww,wh,root=NONE):
self.xmin = 0
self.xmax = ww
self.ymin = wh
self.ymax = 0
if root==NONE:
self.tk=Tk()
else:
self.tk = Toplevel(root)
if ww <= 0.0:
raise "<woyDraw - init> Fehler - Breite der Zeichenfläche muss > 0 sein!"
else:
self.ww = ww
if wh <= 0.0:
raise "<woyDraw - init> Fehler - Höhe der Zeichenfläche muss > 0 sein!"
else:
self.wh = wh
def close(self):
self.tk.destroy()
def settitle(self, title):
self.title = title
def font(self, setfont):
self.font = setfont
def transform(self, myDraw):
for i in myDraw:
i[0] = self.ww * (i[0] - self.xmin)/(self.xmax-self.xmin)
i[1] = self.wh * (i[1] - self.ymax)/(self.ymin-self.ymax)
return myDraw
def area(self, xmin,xmax,ymin,ymax):
if xmin==xmax:
raise "<woyDraw - area> Fehler - xmin darf nicht gleich xmax sein!"
else:
self.xmin = xmin
self.xmax = xmax
if ymin==ymax:
raise "<woyDraw - area> Fehler - ymin darf nicht gleich ymax sein!"
else:
self.ymin = ymin
self.ymax = ymax
def show(self):
self.tk.wm_title(self.title)
self.board = Canvas(self.tk,relief=SUNKEN, bd=2, width=self.ww, height=self.wh)
self.board.pack(fill=BOTH)
Rectangle(self.board, (0,0), (self.ww,self.wh), fill="white", width=1)
b = Button(self.tk, text="Close", font=self.font, command = self.close )
b.pack()
def draw(self,myDraw,myColor,myWidth):
myDraw2 = self.transform(myDraw)
Line(self.board,myDraw2,width=myWidth,fill=myColor)
def rawdraw(self,myDraw,myColor,myWidth):
Line(self.board,myDraw,width=myWidth,fill=myColor)