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


Python Tk.after_idle方法代码示例

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


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

示例1: CameraView

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after_idle [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

示例2: StringView

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after_idle [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

示例3: GraphView

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after_idle [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

示例4: CcdGraphView

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

		self._ccd_id = int(params["ccd_id"]) if "ccd_id" in params else 0

		self._tk = Tk()
		self._text = Text(self._tk, height = CcdGraphView._HEIGHT + 1,
				width = 128, bg = config.COL_GREY_900, fg = config.COL_GREY_100,
				font = (config.FONT, 8))

		self._tk.title("CCD graph view [" + str(self._ccd_id) + ']')
		self._tk.resizable(width = False, height = False)
		self._text.pack(side = tkinter.LEFT, fill = tkinter.Y)

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

		self._file = open("ccd_graph_" + str(self._ccd_id) + '_' \
				+ str(int(time.time() * 1000)) + ".txt", "w")

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

	def on_new_input(self):
		try:
			hex_str = self.get_input()
			if int(hex_str[0:2], 16) != self._ccd_id:
				return
			display = self._get_display_list(hex_str[2:])
		except Exception as e:
			logging.debug(str(e))
			return

		self._file.write(time.strftime("[%x %X]\n"))
		self._text.delete(1.0, tkinter.END)
		for line in display:
			string = line.decode("UTF-8")
			self._text.insert(tkinter.END, string)
			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_display_list(self, hex_str):
		display = [bytearray(b' ' * 128) for i in range(CcdGraphView._HEIGHT)]
		try:
			hex_data = binascii.unhexlify(hex_str)
		except TypeError as e:
			logging.debug(str(e))
			return

		for i in range(128):
			row = int(CcdGraphView._HEIGHT - 1 - hex_data[i] \
					/ CcdGraphView._GROUP_WIDTH);
			display[row][i] = ord('#');
		return display

	_HEIGHT = 26
	_GROUP_WIDTH = 10
开发者ID:hkust-smartcar,项目名称:sc-studio,代码行数:67,代码来源:ccd_graph_view.py

示例5: CcdImageView

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

		self._ccd_id = int(params["ccd_id"]) if "ccd_id" in params else 0
		self._threshold = params["threshold"] if "threshold" in params else 128

		self._tk = Tk()
		self._text = Text(self._tk, width = 128, bg = config.COL_GREY_900,
				fg = config.COL_GREY_100, font = (config.FONT, 5))

		self._tk.title("CCD image view [" + str(self._ccd_id) + ']')
		self._text.pack(side = tkinter.LEFT, fill = tkinter.Y)

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

		self._file = open("ccd_image_" + str(self._ccd_id) + '_' \
				+ str(int(time.time() * 1000)) + ".txt", "w")

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

	def on_new_input(self):
		try:
			hex_str = self.get_input()
			if int(hex_str[0:2], 16) != self._ccd_id:
				return
			line = self._get_line(hex_str[2:])
		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:
			hex_data = binascii.unhexlify(hex_str)
		except TypeError as e:
			logging.debug(str(e))
			return

		line = bytearray(128)
		for i in range(128):
			line[i] = ord('#') if hex_data[i] > self._threshold else ord(' ')
		return line
开发者ID:hkust-smartcar,项目名称:sc-studio,代码行数:63,代码来源:ccd_image_view.py


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