当前位置: 首页>>代码示例>>Python>>正文


Python Tk.protocol方法代码示例

本文整理汇总了Python中tkinter.Tk.protocol方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.protocol方法的具体用法?Python Tk.protocol怎么用?Python Tk.protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.Tk的用法示例。


在下文中一共展示了Tk.protocol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UrlDialog

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
class UrlDialog(threading.Thread):
    def __init__(self, thread=None):
        threading.Thread.__init__(self)
        self.controlThread=thread
        self.dialogRoot=Tk()
        
        if self.dialogRoot == None:
            pass
        
        self.dialogRoot.protocol('WM_DELETE_WINDOW', self.closeBtn)
        
        self.frame=GetUrlFrame(self.dialogRoot, self.controlThread)
        
        if self.frame == None:
            pass
        
    def closeBtn(self):
        self.controlThread.setStop()
        
        
    def closeDialog(self):
        self.dialogRoot.quit()
        self.dialogRoot.destroy()
        print("UrlDialog is terminated.")
 
    def run(self):
        
        print("UrlDialog is show up.")
        self.dialogRoot.mainloop()
开发者ID:fscnick,项目名称:RapidgatorDownloader,代码行数:31,代码来源:DialogThread.py

示例2: main

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
def main():
    ''' Runs main application GUI.
    '''
    logger = get_logger()
    logger.info('pyDEA started as a GUI application.')

    root = Tk()

    root.report_callback_exception = show_error

    # load logo
    if "nt" == os.name:
        iconfile = pkg_resources.resource_filename(PACKAGE, 'pyDEAlogo.ico')
        root.wm_iconbitmap(bitmap=iconfile)
    else:
        iconfile = pkg_resources.resource_filename(PACKAGE, 'pyDEAlogo.gif')
        img = PhotoImage(file=iconfile)
        root.tk.call('wm', 'iconphoto', root._w, img)

    # change background color of all widgets
    s = Style()
    s.configure('.', background=bg_color)

    # run the application
    app = MainFrame(root)
    root.protocol("WM_DELETE_WINDOW", (lambda: ask_quit(app)))

    center_window(root,
                  root.winfo_screenwidth() - root.winfo_screenwidth()*0.15,
                  root.winfo_screenheight() - root.winfo_screenheight()*0.15)

    root.mainloop()
    logger.info('pyDEA exited.')
开发者ID:nishimaomaoxiong,项目名称:pyDEA,代码行数:35,代码来源:main_gui.py

示例3: TkWindowMainLoop

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
class TkWindowMainLoop(Thread):
    '''class for thread that handles Tk window creation and main loop''' 
    
    def __init__(self, client):
        Thread.__init__(self)
        
        self.window = None
        self.canvas = None
        self.client = client
        
        self.start()

    
    def callbackDeleteWindow(self):
        self.client.stop()
        
    def stop(self):
        self.window.quit()
        
    
    def run(self):
        self.window = Tk()
        self.canvas = Canvas(self.window, width=1024, height=768)
        self.canvas.pack()
        
        self.window.protocol("WM_DELETE_WINDOW", self.callbackDeleteWindow)
        
        self.window.mainloop()

    def getWindow(self):
        return self.window
    
    def getCanvas(self):
        return self.canvas
开发者ID:IwfY,项目名称:TkStein3d,代码行数:36,代码来源:tkwindowmainloop.py

示例4: test

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
 def test(self):
     testDir = os.path.dirname(os.path.abspath(sys.modules[__name__].__file__))
     testFileSmall = testDir + "/solvency/2.0/random/spv_20_instance.xbrl"
     application = Tk()
     cntlrWinMain = CntlrWinMain(application)
     application.protocol("WM_DELETE_WINDOW", cntlrWinMain.quit)
     
     cntlrWinMain.setTestMode(True)
     for pluginMethod in pluginClassMethods("DevTesting.GetTestContext"):
         testContext = pluginMethod()
         break
     testContext.checkMemoryOnClose = True
     testContext.dumpFilePrefix = testDir + "/tmp/dump_"
     
     tr = tracker.SummaryTracker()
     
     for idx in range(4):
         print("\nIteration " + str(idx))
         cntlrWinMain.fileOpenFile(testFileSmall)
         cntlrWinMain.logClear()
         cntlrWinMain.fileClose()    
         
         tr.print_diff()  
         if idx > 1:
             assert testContext.diffNumObjects < 8000, "Check for new objects leak"  
开发者ID:acsone,项目名称:Arelle,代码行数:27,代码来源:openCloseWinTest.py

示例5: independentScreen

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
class independentScreen():
	screenDict = {}
	def __init__(self):
		if self._available():
			self.quit()
			return False

		self.root = Tk()
		self.root.protocol("WM_DELETE_WINDOW", self.quit)
		self.root.resizable(0, 0)
		self.root.focus_force()
		independentScreen.screenDict[self._name()] = self

	def _name(self):
		return self.__class__.__name__

	def _available(self):
		return self._name() in independentScreen.screenDict and isinstance(independentScreen.screenDict[self._name()], type(self))

	def quit(self):
		try:
			independentScreen.screenDict[self._name()].root.destroy()
			del independentScreen.screenDict[self._name()]
		except:
			pass
开发者ID:cr0sh,项目名称:NaOH,代码行数:27,代码来源:independentScreen.py

示例6: CameraView

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
class CameraView(View):
    def __init__(self, params):
        super(CameraView, self).__init__(params)

        self._multiplier = int(params["multiplier"]) if "multiplier" in params else 1
        self._multiplier = max(self._multiplier, 1)

        self._tk = Tk()
        self._canvas = Canvas(self._tk, width=80 * self._multiplier, height=60 * self._multiplier)

        self._tk.title("Camera view")
        self._tk.resizable(width=False, height=False)
        self._canvas.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=True)

        self._tk.protocol("WM_DELETE_WINDOW", self.on_press_close)

        self._base_dir = "camera_" + str(int(time.time() * 1000))
        os.makedirs(self._base_dir)

    def run(self):
        super(CameraView, self).run()
        self._tk.mainloop()

    def on_new_input(self):
        try:
            hex_str = self.get_input()
            img = self._get_image(hex_str)
        except Exception as e:
            logging.debug(str(e))
            return
        if img is None:
            return

        bmp = ImageTk.BitmapImage(image=img, foreground="white", background="black")
        self._canvas.create_image(0, 0, image=bmp, anchor=tkinter.NW)
        self._tk_image = bmp

        img.save(self._base_dir + "/" + str(int(time.time() * 1000)) + ".png")

    def on_dismiss(self):
        self._tk.after_idle(self.on_press_close)

    def on_press_close(self):
        self._tk.destroy()
        self.join_io_thread()

    def _get_image(self, hex_str) -> Image:
        try:
            hex_data = binascii.unhexlify(hex_str)
            # Invert data from MCU
            hex_data = bytes([~h & 0xFF for h in hex_data])
        except TypeError as e:
            logging.debug(str(e))
            return

        img = Image.frombytes(mode="1", size=(80, 60), data=hex_data)
        img = img.resize((80 * self._multiplier, 60 * self._multiplier))
        return img
开发者ID:hkust-smartcar,项目名称:sc-studio,代码行数:60,代码来源:camera_view.py

示例7: gui

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
def gui():

    def on_exit():
        if messagebox.askokcancel("Quit", "Do you want to quit?"):
            root.quit()

    root = Tk()
    root.title('Pylinac GUI ' + __version__)
    root.protocol("WM_DELETE_WINDOW", on_exit)
    app = PylinacGUI(master=root)
    app.mainloop()
    root.destroy()
    del root
开发者ID:jrkerns,项目名称:pylinac,代码行数:15,代码来源:py_gui.py

示例8: StringView

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
class StringView(View):
	def __init__(self, params):
		super(StringView, self).__init__(params)

		self._tk = Tk()
		self._text = Text(self._tk, bg = config.COL_GREY_900,
				fg = config.COL_GREY_100)

		self._tk.title("String view")
		self._text.pack(side = tkinter.LEFT, fill = tkinter.Y)

		self._tk.protocol("WM_DELETE_WINDOW", self.on_press_close)

		self._file = open("string_" + str(int(time.time() * 1000)) + ".txt", "w")

	def run(self):
		super(StringView, self).run()
		self._tk.mainloop()

	def on_new_input(self):
		try:
			hex_str = self.get_input()
			line = self._get_line(hex_str)
		except Exception as e:
			logging.debug(str(e))
			return

		string = line.decode("UTF-8")
		self._text.insert(tkinter.END, string)
		self._text.insert(tkinter.END, '\n')
		while self._text.yview()[1] != 1.0:
			self._text.delete(1.0, 2.0)

		self._file.write(time.strftime("[%x %X] "))
		self._file.write(string)
		self._file.write('\n')

	def on_dismiss(self):
		self._tk.after_idle(self.on_press_close)

	def on_press_close(self):
		self._tk.destroy()
		self.join_io_thread()

	def _get_line(self, hex_str):
		try:
			return binascii.unhexlify(hex_str)
		except TypeError as e:
			logging.debug(str(e))
			return
开发者ID:hkust-smartcar,项目名称:sc-studio,代码行数:52,代码来源:string_view.py

示例9: main

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
def main():
	root = Tk()
	root.title("Utagumo")

	root.resizable(width=FALSE, height=FALSE)
	ws = root.winfo_screenwidth()
	hs = root.winfo_screenheight()
	root.geometry('+%d+%d' % (ws/2, hs/2))

	app = UtaGUI(root)
	def shutdown():
		app.cleanup()
		root.destroy()
	root.protocol("WM_DELETE_WINDOW", shutdown)

	logging.info("Running")
	root.mainloop()
	logging.info("Dying")
开发者ID:klaxa,项目名称:utagumo-client,代码行数:20,代码来源:TkClient.py

示例10: main

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
def main():
    images = queue.Queue(maxsize=1)

    def queue_image(image):
        print("Received image")

        save_to_file(image)

        try:
            images.put_nowait(image)
        except queue.Full:
            print("Dropped image, because queue is full")

    if len(sys.argv) > 1:
        with open(sys.argv[1], "rb") as file:
            queue_image(file.read())

    server = ImageServer(queue_image)
    Thread(target=lambda: server.serve_forever()).start()

    root = Tk()

    def cleanup():
        root.destroy()
        server.shutdown()

    root.protocol("WM_DELETE_WINDOW")

    gui = GUI(root)
    gui.pack(fill="both", expand=True)

    def pop_image():
        try:
            data = images.get_nowait()

            gui.set_image(data)
        except queue.Empty:
            pass

        gui.after(1000, pop_image)

    gui.after_idle(pop_image)

    root.mainloop()
开发者ID:cqql,项目名称:camera-obscura,代码行数:46,代码来源:gui.py

示例11: create_admin_window

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
def create_admin_window(bot):
    from tkinter import Tk, Entry, Button

    def clicked():
        bot.loop.call_soon_threadsafe(bot.onAdminMessage, box.get())

    def on_closing():
        bot.loop.call_soon_threadsafe(bot.onAdminMessage, "shutdown")
        root.destroy()

    root = Tk()
    box = Entry(root, width=100)
    box.pack()
    button = Button(root, text="submit", command=clicked)
    button.pack()

    root.protocol("WM_DELETE_WINDOW", on_closing)

    root.mainloop()
开发者ID:sopython,项目名称:rabbit,代码行数:21,代码来源:main.py

示例12: Tk

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
#Code is originally written by Professor Richard Pattis' of
#of University Of Califorina, Irvine. I made some modifications.

#The view module sets up what is seen on the GUI

from tkinter import Tk,Frame,TOP,LEFT,BOTTOM,RAISED,BOTH

# import controller to call/create widgets and position them in the view
import controller


# Construct a simple root window
root = Tk()
root.title("Simulation")
root.protocol("WM_DELETE_WINDOW",quit)
root.resizable(0, 0) #this prevents you from resizing the window

frame = Frame(root)

# Place buttons simply at the top
frame.pack(side=TOP)
controller.reset_button  (frame,text="Reset")  .pack(side=LEFT)
controller.pause_button  (frame,text="Pause")  .pack(side=LEFT)
controller.progress(frame,text="Score: 0",width=25,relief=RAISED).pack(side=LEFT)


# Place canvas in the space below
controller.simulation_canvas(root,width=500,height=300,bg="black").pack(side=BOTTOM,expand=True,fill=BOTH)
开发者ID:kishanrajasekhar,项目名称:UFO-Ambush,代码行数:30,代码来源:view.py

示例13: UISenku

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
class UISenku(Observer):
    '''
    Implements the Graphical User Interface to the Senku.
    
    @ivar _game: the game logic (the model).
    @ivar _root: the main window.
    @ivar _conf_opened: indicates if the configuration window
        is opened.
    '''

    def __init__(self, game):
        '''Constructor of UISenku. Build the main window and the
        main frame.'''
        Observer.__init__(self)
        self._game = game           # game parameters
        self._game.add_observer(self, 'GAME_OVER')
        self._root = Tk()           # root window parameters
        self._root.title('PySenku')
        self._root.protocol("WM_DELETE_WINDOW", self.quit)
        main_frame = Frame(self._root, width=280, height=330, bd=1)
        main_frame.pack()
        BoardArea(self._game, main_frame)
        start_button = Button(main_frame)
        start_button.config(text='Nuevo', command=self.start)
        start_button.grid(row=1, column=0)
        help_button = Button(main_frame)
        help_button.config(text='Mas info...', command=self.open_help)
        help_button.grid(row=1, column=2)
        conf_button = Button(main_frame)
        conf_button.config(text='Configuracion...', command=self.open_config)
        conf_button.grid(row=1, column=3)
        UndoButton(self._game, main_frame)
        self._conf_opened = False
    
    def open_ui(self):
        '''Start the graphic environment.'''    
        self._game.get_all_changes()
        self._root.mainloop()
    
    def start(self):
        '''Reset and start a new game.'''
        self._game.restart()
    
    def open_help(self):
        '''Open the help window.'''
        showinfo('Mas info...', HELP_TEXT)
    
    def open_config(self):
        '''Open the configuration window.'''
        if not self._conf_opened:
            self._conf_opened = True
            ConfigWindow().mainloop()
    
    def update(self, aspect, value):
        '''GAME_OVER is the only notification that
        this class receive.'''
        if askyesno('Juego Finalizado', 'Quedaron ' + str(value) + \
            ' fichas.\n \n Comenzar otra partida?'):
            self.start()
    
    def quit(self):
        '''Handler for window close attempt.'''    
        if CONFIG['CONFIRM_EXIT']:
            if askyesno('Salir', 'Realmente desea salir?'): 
                self._root.destroy()
        else:
            self._root.destroy()
开发者ID:ngarbezza,项目名称:pysenku,代码行数:69,代码来源:pysenku-0.5.py

示例14: Label

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
pastes_heading = Label(root, text="Pastes", font=(None, 15))
pastes_heading.pack()

pastes_frame = Frame(root, borderwidth=2, height=5000)

paste_elements = [
    {
        "text": Label(pastes_frame, text=""),
        "date": Label(pastes_frame, text=""),
        "button": Button(pastes_frame, text="Copy"),
    }
    for i in range(10)
]

for index, element in enumerate(paste_elements):
    element["text"].grid(row=index, column=0, columnspan=2)
    pastes_frame.pack()
    element["date"].grid(row=index, column=2)
    pastes_frame.pack()
    element["button"].grid(row=index, column=3)
    pastes_frame.pack()

delete_button = Button(root, text="Delete all pastes", command=delete_all)
delete_button.pack()

thread = Thread(target=update)
thread.start()

root.protocol("WM_DELETE_WINDOW", stop)
root.mainloop()
开发者ID:Arya04,项目名称:hello-world,代码行数:32,代码来源:gui.py

示例15: GraphView

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import protocol [as 别名]
class GraphView(View):
	WIN_PADDING_Y = 16
	POINT_MARGIN = 2

	def __init__(self, params):
		super(GraphView, self).__init__(params)

		self._ids = params["ids"] if "ids" in params else ""
		self._ids = [int(i) for i in self._ids.split(' ')]
		self._labels = params["labels"] if "labels" in params else ""
		self._labels = [l for l in self._labels.split(' ')]
		self._colors = [c for c in params["colors"].split(' ')] if "colors" in \
				params else None
		if not self._colors:
			self._colors = self._get_auto_colors(len(self._ids))
		if not len(self._ids) == len(self._labels) == len(self._colors):
			raise RuntimeError("ids, labels and colors must share the same size")

		self._min = float(params["min"]) if "min" in params else -1000
		self._max = float(params["max"]) if "max" in params else 1000
		if self._min > self._max:
			self._min, self._max = self._max, self._min
		self._diff = abs(self._max - self._min)

		self._data = [_GraphData() for _ in range(len(self._ids))]
		self._data_view = [_GraphDataView(self._colors[i]) for i in range(
				len(self._ids))]
		self._graph_x = 0

		self._tk = Tk()
		self._tk.title("Graph view %s" % str(self._labels))

		self._canvas = Canvas(self._tk, width = 640, height = 480)
		self._canvas.pack(fill = tkinter.BOTH, expand = 1)

		self._tk.update()
		self._win_size = self._tk.winfo_width(), self._tk.winfo_height()
		# graph_rect only works as providing the area but not coord
		self._graph_rect = self._win_size
		self._tk.minsize(320, 240)
		self._tk.protocol("WM_DELETE_WINDOW", self.on_press_close)

		self._tk.bind("<Configure>", self.on_config)
		self._canvas.config(background = config.COL_GREY_900)

		self._full_redraw()

		self._file = open("graph_%s_%i.csv" % (str(self._labels),
				int(time.time() * 1000)), "w")
		self._file.write(','.join(self._labels) + '\n')

		self._tk.after(16, self._refresh)

	def run(self):
		super(GraphView, self).run()
		self._tk.mainloop()

	def on_new_input(self):
		try:
			hex_data = binascii.unhexlify(self.get_input())
		except TypeError as e:
			logging.debug(str(e))
			return

		count = int(len(hex_data) / GraphView._MSG_SIZE)
		for i in (x * 6 for x in range(count)):
			if hex_data[i] in self._ids:
				value_type = hex_data[i + 1]
				value_bytes = hex_data[i + 2:i + 6]
				if value_type == GraphView._MSG_TYPE_INT:
					value = int.from_bytes(value_bytes, byteorder = "big",
							signed = True)
				elif value_type == GraphView._MSG_TYPE_FLOAT:
					value = struct.unpack(">f", value_bytes)[0]
				else:
					logging.error("Unknown type: " + str(value_type))
					continue
				self._tk.after_idle(self._put_value, hex_data[i], value)

	def on_dismiss(self):
		self._tk.after_idle(self.on_press_close)

	def on_press_close(self):
		self._tk.destroy()
		self.join_io_thread()

	def on_config(self, event):
		win_size = (event.width, event.height)
		if win_size != self._win_size:
			self._win_size = win_size
			self._full_redraw()

	def is_test_input(self):
		return False

	def gen_test_input(self):
		while True:
			for i in range(int(self._min), int(self._max)):
				sleep(0.1)
				yield "0000%08x" % (random.randrange(-100, 100) & 0xFFFFFFFF) \
#.........这里部分代码省略.........
开发者ID:hkust-smartcar,项目名称:sc-studio,代码行数:103,代码来源:graph_view.py


注:本文中的tkinter.Tk.protocol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。