本文整理汇总了Python中Tkinter.NW属性的典型用法代码示例。如果您正苦于以下问题:Python Tkinter.NW属性的具体用法?Python Tkinter.NW怎么用?Python Tkinter.NW使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Tkinter
的用法示例。
在下文中一共展示了Tkinter.NW属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_preview
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def update_preview(self, psize):
# Safety check: Ignore calls during construction/destruction.
if not self.init_done: return
# Copy latest user settings to the lens object.
self.lens.fov_deg = self.f.get()
self.lens.radius_px = self.r.get()
self.lens.center_px[0] = self.x.get()
self.lens.center_px[1] = self.y.get()
# Re-scale the image to match the canvas size.
# Note: Make a copy first, because thumbnail() operates in-place.
self.img_sc = self.img.copy()
self.img_sc.thumbnail(psize, Image.NEAREST)
self.img_tk = ImageTk.PhotoImage(self.img_sc)
# Re-scale the x/y/r parameters to match the preview scale.
pre_scale = float(psize[0]) / float(self.img.size[0])
x = self.x.get() * pre_scale
y = self.y.get() * pre_scale
r = self.r.get() * pre_scale
# Clear and redraw the canvas.
self.preview.delete('all')
self.preview.create_image(0, 0, anchor=tk.NW, image=self.img_tk)
self.preview.create_oval(x-r, y-r, x+r, y+r,
outline='#C00000', width=3)
# Make a combined label/textbox/slider for a given variable:
示例2: _write
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def _write(self, ch, fg, bg):
if self.x == self.width:
self.x = 0
self.y+=1
if self.y == self.height:
[self.canvas.move(x,0,-fontHeight) for x in self.canvas.find_all()]
self.y-=1
canvasX = self.x*fontWidth + 1
canvasY = self.y*fontHeight + 1
items = self.canvas.find_overlapping(canvasX, canvasY, canvasX+2, canvasY+2)
if items:
[self.canvas.delete(item) for item in items]
if bg:
self.canvas.create_rectangle(canvasX, canvasY, canvasX+fontWidth-1, canvasY+fontHeight-1, fill=bg, outline=bg)
self.canvas.create_text(canvasX, canvasY, anchor=Tkinter.NW, font=ttyFont, text=ch, fill=fg)
self.x+=1
示例3: __init__
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def __init__(self, master, im, value=128):
tkinter.Frame.__init__(self, master)
self.image = im
self.value = value
self.canvas = tkinter.Canvas(self, width=im.size[0], height=im.size[1])
self.backdrop = ImageTk.PhotoImage(im)
self.canvas.create_image(0, 0, image=self.backdrop, anchor=tkinter.NW)
self.canvas.pack()
scale = tkinter.Scale(self, orient=tkinter.HORIZONTAL, from_=0, to=255,
resolution=1, command=self.update_scale,
length=256)
scale.set(value)
scale.bind("<ButtonRelease-1>", self.redraw)
scale.pack()
# uncomment the following line for instant feedback (might
# be too slow on some platforms)
# self.redraw()
示例4: __init__
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def __init__(self, master, image):
tkinter.Canvas.__init__(self, master,
width=image.size[0], height=image.size[1])
# fill the canvas
self.tile = {}
self.tilesize = tilesize = 32
xsize, ysize = image.size
for x in range(0, xsize, tilesize):
for y in range(0, ysize, tilesize):
box = x, y, min(xsize, x+tilesize), min(ysize, y+tilesize)
tile = ImageTk.PhotoImage(image.crop(box))
self.create_image(x, y, image=tile, anchor=tkinter.NW)
self.tile[(x, y)] = box, tile
self.image = image
self.bind("<B1-Motion>", self.paint)
示例5: Load_T2
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def Load_T2(self, event=None):
"""
"""
self.T2filename = filedialog.askopenfilename()
nib_vol = nib.load(self.T2filename)
self.affine = nib_vol.affine
self.T2_vol = nib_vol.get_data()
mid_slice = self.T2_vol.shape[2]//2
true_size = self.T2_vol.shape[:2]
size = (self.T2_canvas.winfo_width(), self.T2_canvas.winfo_height())
size = (size[0], int(true_size[0]/true_size[1])*size[1]) if size[0] < size[1] else (int(true_size[1]/true_size[0])*size[0], size[1])
self.T2_canvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(self.T2_vol[:,:,mid_slice].T)).resize(size))
self.T2_canvas.create_image(0, 0, image=self.T2_canvas_image, anchor=tk.NW)
self.update_main_view(self.T2_vol, self.T2_vol.shape[0]//2, self.T2_vol.shape[1]//2, self.T2_vol.shape[2]//2)
self.init_scales(self.T2_vol)
示例6: Load_T1
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def Load_T1(self, event=None):
self.T1filename = filedialog.askopenfilename()
nib_vol = nib.load(self.T1filename)
self.affine = nib_vol.affine
self.T1_vol = nib_vol.get_data()
mid_slice = self.T1_vol.shape[2]//2
true_size = self.T1_vol.shape[:2]
size = (self.T1_canvas.winfo_width(), self.T1_canvas.winfo_height())
size = (size[0], int(true_size[0]/true_size[1])*size[1]) if size[0] < size[1] else (int(true_size[1]/true_size[0])*size[0], size[1])
self.T1_canvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(self.T1_vol[:,:,mid_slice].T)).resize(size))
self.T1_canvas.create_image(0, 0, image=self.T1_canvas_image, anchor=tk.NW)
self.update_main_view(self.T1_vol, self.T1_vol.shape[0]//2, self.T1_vol.shape[1]//2, self.T1_vol.shape[2]//2)
self.init_scales(self.T1_vol)
示例7: Load_Flair
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def Load_Flair(self, event=None):
self.Flairfilename = filedialog.askopenfilename()
nib_vol = nib.load(self.Flairfilename)
self.affine = nib_vol.affine
self.Flair_vol = nib_vol.get_data()
mid_slice = self.Flair_vol.shape[2]//2
true_size = self.Flair_vol.shape[:2]
size = (self.Flair_canvas.winfo_width(), self.Flair_canvas.winfo_height())
size = (size[0], int(true_size[0]/true_size[1])*size[1]) if size[0] < size[1] else (int(true_size[1]/true_size[0])*size[0], size[1])
self.Flair_canvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(self.Flair_vol[:,:,mid_slice].T)).resize(size))
self.Flair_canvas.create_image(0, 0, image=self.Flair_canvas_image, anchor=tk.NW)
self.update_main_view(self.Flair_vol, self.Flair_vol.shape[0]//2, self.Flair_vol.shape[1]//2, self.Flair_vol.shape[2]//2)
self.init_scales(self.Flair_vol)
示例8: draw_image
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def draw_image(self, imgpil):
self.root.photo1 = _ImageTk.PhotoImage(image=imgpil) # not file=imgpath
(scrwide, scrhigh) = self.root.maxsize() # wm screen size x,y
scrhigh -= 200 # leave room for top display/button at max photo size
imgwide = self.root.photo1.width() # size in pixels
imghigh = self.root.photo1.height() # same as imgpil.size
fullsize = (0, 0, imgwide, imghigh) # scrollable
viewwide = min(imgwide, scrwide) # viewable
viewhigh = min(imghigh, scrhigh)
self.canvas1.delete('all') # clear prior photo
self.canvas1.config(height=viewhigh, width=viewwide) # viewable window size
self.canvas1.config(scrollregion=fullsize) # scrollable area size
self.root.img = self.canvas1.create_image(0, 0, image=self.root.photo1,
anchor=_Tk.NW)
if imgwide <= scrwide and imghigh <= scrhigh: # too big for display?
self.root.state('normal') # no: win size per img
elif (_sys.platform)[:3] == 'win':
# do windows fullscreen
self.root.state('zoomed') # others use geometry( )
示例9: set_canvas_background
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def set_canvas_background(self, image):
if self.background_label is None:
# initialize background image label (first call)
#img = self.current_state.screenshot_rs
#bg_img_tk = numpy_to_tk_image(np.zeros(img.shape))
img_heatmap = self._generate_heatmap()
img_heatmap_rs = ia.imresize_single_image(img_heatmap, (img_heatmap.shape[0]*ZOOM_FACTOR, img_heatmap.shape[1]*ZOOM_FACTOR), interpolation="nearest")
bg_img_tk = numpy_to_tk_image(img_heatmap_rs)
self.background_label = Tkinter.Label(self.canvas, image=bg_img_tk)
self.background_label.place(x=0, y=0, relwidth=1, relheight=1, anchor=Tkinter.NW)
self.background_label.image = bg_img_tk
#print("image size", image.shape)
#print("image height, width", image.to_array().shape)
image_rs = ia.imresize_single_image(image, (image.shape[0]*ZOOM_FACTOR, image.shape[1]*ZOOM_FACTOR), interpolation="nearest")
image_tk = numpy_to_tk_image(image_rs)
self.background_label.configure(image=image_tk)
self.background_label.image = image_tk
示例10: set_canvas_background
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def set_canvas_background(self, image):
if self.background_label is None:
# initialize background image label (first call)
#img = self.current_state.screenshot_rs
#bg_img_tk = numpy_to_tk_image(np.zeros(img.shape))
img_heatmap = self._generate_heatmap()
img_heatmap_rs = ia.imresize_single_image(img_heatmap, (img_heatmap.shape[0]*self.zoom_factor, img_heatmap.shape[1]*self.zoom_factor), interpolation="nearest")
bg_img_tk = numpy_to_tk_image(img_heatmap_rs)
self.background_label = Tkinter.Label(self.canvas, image=bg_img_tk)
self.background_label.place(x=0, y=0, relwidth=1, relheight=1, anchor=Tkinter.NW)
self.background_label.image = bg_img_tk
#print("image size", image.shape)
#print("image height, width", image.to_array().shape)
image_rs = ia.imresize_single_image(image, (image.shape[0]*self.zoom_factor, image.shape[1]*self.zoom_factor), interpolation="nearest")
image_tk = numpy_to_tk_image(image_rs)
self.background_label.configure(image=image_tk)
self.background_label.image = image_tk
示例11: __init__
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def __init__(self, root, rect, frame_color, screen_cap, queue):
""" Accepts rect as (x,y,w,h) """
self.root = root
self.root.tk.call('tk', 'scaling', 0.5)
tk.Toplevel.__init__(self, self.root, bg="red", bd=0)
self.queue = queue
self.check_close_after = None
## Set toplevel geometry, remove borders, and push to the front
self.geometry("{2}x{3}+{0}+{1}".format(*rect))
self.overrideredirect(1)
self.attributes("-topmost", True)
## Create canvas and fill it with the provided image. Then draw rectangle outline
self.canvas = tk.Canvas(
self,
width=rect[2],
height=rect[3],
bd=0,
bg="blue",
highlightthickness=0)
self.tk_image = ImageTk.PhotoImage(Image.fromarray(screen_cap))
self.canvas.create_image(0, 0, image=self.tk_image, anchor=tk.NW)
self.canvas.create_rectangle(
2,
2,
rect[2]-2,
rect[3]-2,
outline=frame_color,
width=4)
self.canvas.pack(fill=tk.BOTH, expand=tk.YES)
## Lift to front if necessary and refresh.
self.lift()
self.update()
示例12: __init__
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def __init__(self, root, rect, frame_color, screen_cap):
""" Accepts rect as (x,y,w,h) """
self.root = root
tk.Toplevel.__init__(self, self.root, bg="red", bd=0)
## Set toplevel geometry, remove borders, and push to the front
self.geometry("{2}x{3}+{0}+{1}".format(*rect))
self.overrideredirect(1)
self.attributes("-topmost", True)
## Create canvas and fill it with the provided image. Then draw rectangle outline
self.canvas = tk.Canvas(
self,
width=rect[2],
height=rect[3],
bd=0,
bg="blue",
highlightthickness=0)
self.tk_image = ImageTk.PhotoImage(Image.fromarray(screen_cap[..., [2, 1, 0]]))
self.canvas.create_image(0, 0, image=self.tk_image, anchor=tk.NW)
self.canvas.create_rectangle(
2,
2,
rect[2]-2,
rect[3]-2,
outline=frame_color,
width=4)
self.canvas.pack(fill=tk.BOTH, expand=tk.YES)
## Lift to front if necessary and refresh.
self.lift()
self.update()
示例13: redraw
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def redraw(self, event=None):
# create overlay (note the explicit conversion to mode "1")
im = self.image.point(lambda v, t=self.value: v >= t, "1")
self.overlay = ImageTk.BitmapImage(im, foreground="green")
# update canvas
self.canvas.delete("overlay")
self.canvas.create_image(0, 0, image=self.overlay, anchor=tkinter.NW,
tags="overlay")
# --------------------------------------------------------------------
# main
示例14: update_main_view
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def update_main_view(self, vol, slice1, slice2, slice3):
"""
"""
self.main_vol = vol
true_size = vol.shape[:2]
size = (self.AxialCanvas.winfo_width(), self.AxialCanvas.winfo_height())
size = (size[0], int(true_size[0]/true_size[1])*size[1]) if size[0] < size[1] else (int(true_size[1]/true_size[0])*size[0], size[1])
self.AxialCanvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(vol[:,:,slice3].T)).resize(size))
self.AxialCanvas.create_image(0, 0, image=self.AxialCanvas_image, anchor=tk.NW)
true_size = (vol.shape[0], vol.shape[2])
size = (self.AxialCanvas.winfo_width(), self.AxialCanvas.winfo_height())
size = (size[0], int(true_size[0]/true_size[1])*size[1]) if size[0] < size[1] else (int(true_size[1]/true_size[0])*size[0], size[1])
self.SagitalCanvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(np.flipud(vol[:, slice2, :].T))).resize(size))
self.SagitalCanvas.create_image(0, 0, image=self.SagitalCanvas_image, anchor=tk.NW)
true_size = (vol.shape[1], vol.shape[2])
size = (self.AxialCanvas.winfo_width(), self.AxialCanvas.winfo_height())
size = (size[0], int(true_size[0]/true_size[1])*size[1]) if size[0] < size[1] else (int(true_size[1]/true_size[0])*size[0], size[1])
self.CorronalCanvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(np.flipud(vol[slice1, :, :].T))).resize(size))
self.CorronalCanvas.create_image(0, 0, image=self.CorronalCanvas_image, anchor=tk.NW)
示例15: Get_Segmentation
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import NW [as 别名]
def Get_Segmentation(self, event=None):
try:
if (self.T1_vol != None) and (self.T2_vol != None) and (self.T1ce_vol != None) and (self.Flair_vol != None):
pass
else:
pass
except:
ValueError
self.prediction = get_brainsegmentation.get_segmentation(self.T1filename,
self.T2filename,
self.T1cefilename,
self.Flairfilename)
# self.prediction = nib.load(os.path.join(os.path.dirname(self.T2filename), 'seg.nii.gz')).get_data()
mid_slice = self.prediction.shape[2]//2
true_size = self.T1ce_vol.shape[:2]
size = (self.T1ce_canvas.winfo_width(), self.T1ce_canvas.winfo_height())
size = (size[0], int(true_size[0]/true_size[1])*size[1]) if size[0] < size[1] else (int(true_size[1]/true_size[0])*size[0], size[1])
self.seg_canvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(self.prediction[:,:,mid_slice].T)).resize(size))
self.seg_canvas.create_image(0, 0, image=self.seg_canvas_image, anchor=tk.NW)
self.update_main_view(self.prediction, self.prediction.shape[0]//2, self.prediction.shape[1]//2, self.prediction.shape[2]//2)
pass