Python Tkinter.NW Examples
The following are 26
code examples of Tkinter.NW().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Tkinter
, or try the search function
.
Example #1
Source File: DeepBrainSegUI.py From DeepBrainSeg with MIT License | 6 votes |
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)
Example #2
Source File: common.py From self-driving-truck with MIT License | 6 votes |
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
Example #3
Source File: annotate_attributes.py From self-driving-truck with MIT License | 6 votes |
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
Example #4
Source File: annotate_street_boundaries.py From self-driving-truck with MIT License | 6 votes |
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
Example #5
Source File: cs1media.py From cs101 with GNU General Public License v3.0 | 6 votes |
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( )
Example #6
Source File: tkvt100.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
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
Example #7
Source File: tkvt100.py From python-for-android with Apache License 2.0 | 6 votes |
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
Example #8
Source File: fisheye.py From DualFisheye with MIT License | 6 votes |
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:
Example #9
Source File: DeepBrainSegUI.py From DeepBrainSeg with MIT License | 6 votes |
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)
Example #10
Source File: DeepBrainSegUI.py From DeepBrainSeg with MIT License | 6 votes |
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)
Example #11
Source File: painter.py From mxnet-lambda with Apache License 2.0 | 6 votes |
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)
Example #12
Source File: thresholder.py From mxnet-lambda with Apache License 2.0 | 6 votes |
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()
Example #13
Source File: tkvt100.py From learn_python3_spider with MIT License | 6 votes |
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
Example #14
Source File: tkvt100.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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
Example #15
Source File: DeepBrainSegUI.py From DeepBrainSeg with MIT License | 5 votes |
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)
Example #16
Source File: thresholder.py From mxnet-lambda with Apache License 2.0 | 5 votes |
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
Example #17
Source File: DeepBrainSegUI.py From DeepBrainSeg with MIT License | 5 votes |
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
Example #18
Source File: tkgui.py From ATX with Apache License 2.0 | 5 votes |
def draw_image(self, image): self._image = image self._size = (width, height) = image.size w, h = int(width*self._ratio), int(height*self._ratio) image = image.copy() image.thumbnail((w, h), Image.ANTIALIAS) tkimage = ImageTk.PhotoImage(image) self._tkimage = tkimage # keep a reference self.canvas.config(width=w, height=h) self.canvas.create_image(0, 0, anchor=tk.NW, image=tkimage)
Example #19
Source File: tkgui.py From ATX with Apache License 2.0 | 5 votes |
def draw_image(self, image): self._image = image self._size = (width, height) = image.size w, h = int(width*self._ratio), int(height*self._ratio) # print w, h image = image.copy() image.thumbnail((w, h), Image.ANTIALIAS) tkimage = ImageTk.PhotoImage(image) self._tkimage = tkimage # keep a reference self.canvas.config(width=w, height=h) self.canvas.create_image(0, 0, anchor=tk.NW, image=tkimage)
Example #20
Source File: slam.py From slam with Apache License 2.0 | 5 votes |
def showMap(img1): global IMG IMG = img1 if(img1 != None): can.create_image(0,0,anchor=NW,image = img1)
Example #21
Source File: menotexport-gui.py From Menotexport with GNU General Public License v3.0 | 5 votes |
def addPathFrame(self): frame=Frame(self) frame.pack(fill=tk.X,expand=0,side=tk.TOP,padx=8,pady=5) frame.columnconfigure(1,weight=1) #------------------Database file------------------ label=tk.Label(frame,text='Mendeley Data file:',\ bg='#bbb') label.grid(row=0,column=0,\ sticky=tk.W,padx=8) self.db_entry=tk.Entry(frame) self.db_entry.grid(row=0,column=1,sticky=tk.W+tk.E,padx=8) self.db_button=tk.Button(frame,text='Open',command=self.openFile) self.db_button.grid(row=0,column=2,padx=8,sticky=tk.E) hint=''' Default location on Linux: ~/.local/share/data/Mendeley\ Ltd./Mendeley\ Desktop/your_email@www.mendeley.com.sqlite Default location on Windows: C:\Users\Your_name\AppData\Local\Mendeley Ltd\Mendeley Desktop\your_email@www.mendeley.com.sqlite''' hint_label=tk.Label(frame,text=hint,\ justify=tk.LEFT,anchor=tk.NW) hint_label.grid(row=1,column=0,columnspan=3,\ sticky=tk.W,padx=8) #--------------------Output dir-------------------- label2=tk.Label(frame,text='Output folder:',\ bg='#bbb') label2.grid(row=2,column=0,\ sticky=tk.W,padx=8) self.out_entry=tk.Entry(frame) self.out_entry.grid(row=2,column=1,sticky=tk.W+tk.E,padx=8) self.out_button=tk.Button(frame,text='Choose',command=self.openDir) self.out_button.grid(row=2,column=2,padx=8,sticky=tk.E)
Example #22
Source File: PlatformManagerWindows.py From lackey with MIT License | 5 votes |
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()
Example #23
Source File: PlatformManagerDarwin.py From lackey with MIT License | 5 votes |
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()
Example #24
Source File: DeepBrainSegUI.py From DeepBrainSeg with MIT License | 4 votes |
def update_main_view_overlay(self, vol, prediction, slice1, slice2, slice3, alpha_val=0.5): """ """ self.main_vol = vol pred = prediction[:,:,slice3].T alpha = np.zeros_like(pred).astype("float") alpha[pred > 0] = alpha_val alpha = alpha[..., None] print (np.unique(alpha)) 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]) img = (1 - alpha)*plot_normalize(create_img(vol[:,:,slice3].T)) + alpha*create_mask(pred) self.AxialCanvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(img)).resize(size)) self.AxialCanvas.create_image(0, 0, image=self.AxialCanvas_image, anchor=tk.NW) pred = np.flipud(prediction[:,slice2, :].T) alpha = np.zeros_like(pred).astype("float") alpha[pred > 0] = alpha_val alpha = alpha[..., None] 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]) img = (1 - alpha)*plot_normalize(create_img(np.flipud(vol[:,slice2,:].T))) + alpha*create_mask(pred) self.SagitalCanvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(img)).resize(size)) self.SagitalCanvas.create_image(0, 0, image=self.SagitalCanvas_image, anchor=tk.NW) pred = np.flipud(prediction[slice1,:,:].T) alpha = np.zeros_like(pred).astype("float") alpha[pred > 0] = alpha_val alpha = alpha[..., None] 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]) img = (1 - alpha)*plot_normalize(create_img(np.flipud(vol[slice1, :, :].T))) + alpha*create_mask(pred) self.CorronalCanvas_image = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(plot_normalize(img)).resize(size)) self.CorronalCanvas.create_image(0, 0, image=self.CorronalCanvas_image, anchor=tk.NW) # =================================================================
Example #25
Source File: tkgui.py From ATX with Apache License 2.0 | 4 votes |
def _init_items(self): """ .---------------. | Ctrl | Screen | |------| | | Code | | | | | """ root = self._root root.resizable(0, 0) frm_control = tk.Frame(root, bg='#bbb') frm_control.grid(column=0, row=0, padx=5, sticky=tk.NW) frm_screen = tk.Frame(root, bg='#aaa') frm_screen.grid(column=1, row=0) frm_screenshot = tk.Frame(frm_control) frm_screenshot.grid(column=0, row=0, sticky=tk.W) tk.Label(frm_control, text='-'*30).grid(column=0, row=1, sticky=tk.EW) frm_code = tk.Frame(frm_control) frm_code.grid(column=0, row=2, sticky=tk.EW) self._btn_refresh = tk.Button(frm_screenshot, textvariable=self._refresh_text, command=self._refresh_screen) self._btn_refresh.grid(column=0, row=0, sticky=tk.W) # tk.Button(frm_screenshot, text="Wakeup", command=self._device.wakeup).grid(column=0, row=1, sticky=tk.W) tk.Button(frm_screenshot, text=u"保存选中区域", command=self._save_crop).grid(column=0, row=1, sticky=tk.W) # tk.Button(frm_screenshot, text="保存截屏", command=self._save_screenshot).grid(column=0, row=2, sticky=tk.W) frm_checkbtns = tk.Frame(frm_screenshot) frm_checkbtns.grid(column=0, row=3, sticky=(tk.W, tk.E)) tk.Checkbutton(frm_checkbtns, text="Auto refresh", variable=self._auto_refresh_var, command=self._run_check_refresh).grid(column=0, row=0, sticky=tk.W) tk.Checkbutton(frm_checkbtns, text="UI detect", variable=self._uiauto_detect_var).grid(column=1, row=0, sticky=tk.W) frm_code_editor = tk.Frame(frm_code) frm_code_editor.grid(column=0, row=0, sticky=(tk.W, tk.E)) tk.Label(frm_code_editor, text='Generated code').grid(column=0, row=0, sticky=tk.W) tk.Entry(frm_code_editor, textvariable=self._gencode_text, width=30).grid(column=0, row=1, sticky=tk.W) tk.Label(frm_code_editor, text='Save file name').grid(column=0, row=2, sticky=tk.W) tk.Entry(frm_code_editor, textvariable=self._genfile_name, width=30).grid(column=0, row=3, sticky=tk.W) tk.Label(frm_code_editor, text='Extention name').grid(column=0, row=4, sticky=tk.W) tk.Entry(frm_code_editor, textvariable=self._fileext_text, width=30).grid(column=0, row=5, sticky=tk.W) frm_code_btns = tk.Frame(frm_code) frm_code_btns.grid(column=0, row=2, sticky=(tk.W, tk.E)) tk.Button(frm_code_btns, text='Run', command=self._run_code).grid(column=0, row=0, sticky=tk.W) self._btn_runedit = tk.Button(frm_code_btns, state=tk.DISABLED, text='Insert and Run', command=self._run_and_insert) self._btn_runedit.grid(column=1, row=0, sticky=tk.W) tk.Button(frm_code, text='Select File', command=self._run_selectfile).grid(column=0, row=4, sticky=tk.W) tk.Label(frm_code, textvariable=self._attachfile_text).grid(column=0, row=5, sticky=tk.W) tk.Button(frm_code, text='Reset', command=self._reset).grid(column=0, row=6, sticky=tk.W) self.canvas = tk.Canvas(frm_screen, bg="blue", bd=0, highlightthickness=0, relief='ridge') self.canvas.grid(column=0, row=0, padx=10, pady=10) self.canvas.bind("<Button-1>", self._stroke_start) self.canvas.bind("<B1-Motion>", self._stroke_move) self.canvas.bind("<B1-ButtonRelease>", self._stroke_done) self.canvas.bind("<Motion>", self._mouse_move)
Example #26
Source File: recipe-578874.py From code with MIT License | 4 votes |
def test(): root = tk.Tk() scrollbar = simultaneousScrollbar(root, orient=tk.HORIZONTAL) scrollbar.pack(side=tk.TOP, fill=tk.X) emptySpace = tk.Frame(root, height=18) emptySpace.pack() tk.Label(root, text='First scrolled frame:').pack(anchor=tk.W) canvas1 = tk.Canvas(root, width=300, height=100) canvas1.pack(anchor=tk.NW) frame1= tk.Frame(canvas1) frame1.pack() for i in range(20): tk.Label(frame1, text="Label "+str(i)).pack(side=tk.LEFT) canvas1.create_window(0, 0, window=frame1, anchor='nw') canvas1.update_idletasks() canvas1['scrollregion'] = (0,0,frame1.winfo_reqwidth(), frame1.winfo_reqheight()) tk.Label(root, text='Second scrolled frame:').pack(anchor=tk.W) canvas2 = tk.Canvas(root,width=300, height=100) canvas2.pack(anchor=tk.NW) frame2= tk.Frame(canvas2) frame2.pack() for i in range(20): tk.Label(frame2, text="Label "+str(i)).pack(side=tk.LEFT) canvas2.create_window(0, 0, window=frame2, anchor='nw') canvas2.update_idletasks() canvas2['scrollregion'] = (0,0,frame2.winfo_reqwidth(), frame2.winfo_reqheight()) scrollbar.add_ScrollableArea(canvas1,canvas2) MouseWheel(root).add_scrolling(canvas1, xscrollbar=scrollbar) MouseWheel(root).add_scrolling(canvas2, xscrollbar=scrollbar) root.mainloop()