本文整理汇总了Python中tkinter.Tk.winfo_width方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.winfo_width方法的具体用法?Python Tk.winfo_width怎么用?Python Tk.winfo_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Tk
的用法示例。
在下文中一共展示了Tk.winfo_width方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import winfo_width [as 别名]
def main():
root = Tk()
h = root.winfo_height()
w = root.winfo_width()
x = root.winfo_screenwidth()
y = root.winfo_screenheight()
root.geometry('%dx%d+%d+%d' % (w, h, x/2, y/2))
app = Tool(root)
# root.mainloop()
return(root)
示例2: GraphView
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import winfo_width [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) \
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import winfo_width [as 别名]
class Gem:
def __init__(self):
self.frame = Tk();
self.frame.resizable(False, False)
self.status = 1
self.scorePlayerA = 0
self.scorePlayerB = 0
self.scoreRoundA = 0
self.scoreRoundB = 0
self.countRound = 0
self.quitMatch = 0
self.isQuitRound = 0
self.canvas_after_2 = 0
self.canvas_after_1 = 0
self.isPause = 0
#register event
self.frame.bind("<F4>", self.quitGame)
self.frame.bind("<F5>", self.pauseGame)
self.frame.protocol("WM_DELETE_WINDOW", self.on_closing)
self.registerKeyboard()
def setName(self, title):
self.frame.title(title)
def setBall(self, ball):
self.ball = ball
def setLeftBar(self, bar):
self.leftBar = bar
def setRightBar(self, bar):
self.rightBar = bar
def run(self):
self.frame.mainloop()
def getFrame(self):
return self.frame;
def getCanvas(self):
return self.canvas
def setSize(self, size):
self.frame.geometry(("%dx%d")%(size[0], size[1]))
self.frame.update()
def getSize(self):
return (self.frame.winfo_width(), self.frame.winfo_height())
def setBackground(self, color):
self.background = color
def setPlayers(self, players):
self.players = players
def setScoreBoard(self):
players = self.players
size = self.getSize()
mid = round(size[0]/2)
# Board
self.canvas.create_rectangle(mid - 100, 0, mid + 100, 35, fill="grey58", outline="white", tag="boarda")
# Player name 1
self.canvas.create_text(mid - 80, 15, text=players[0], fill="magenta2", tag="boardb")
# Round score 1
r1 = players[0]+"a"
self.canvas.create_text(mid - 80, 28, text="0", fill="pale green", tag="scoreplayera")
# Player name 2
self.canvas.create_text(mid + 80, 15, text=players[1], fill="magenta2", tag="boardc")
# Round score 2
self.canvas.create_text(mid + 80, 28, text="0", fill="pale green", tag="scoreplayerb")
# Box score 1
self.canvas.create_rectangle(mid - 50, 5, mid - 10, 25, fill="thistle3", outline="white", tag="boardd")
# Score 1
self.canvas.create_text(mid - 30, 15, text="000", fill="cyan", tag=players[0])
# Box score 2
self.canvas.create_rectangle(mid + 10, 5, mid + 50, 25, fill="thistle3", outline="white", tag="boarde")
# Score 2
self.canvas.create_text(mid + 30, 15, text="000", fill="cyan", tag=players[1])
self.canvas.pack()
self.frame.update()
def clearScoreBoard(self):
self.canvas.delete(self.players[0])
self.canvas.delete(self.players[1])
self.canvas.delete("boarda")
#.........这里部分代码省略.........
示例4: reactToClick
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import winfo_width [as 别名]
#.........这里部分代码省略.........
self.buttonSaveResult = Button(self.frameResultSequence, text=" Save ")
self.textResultSequence = ScrolledText(self.frameResultSequence, height=10)
self.buttonOptimize.grid(column=0, row=0, pady=5, sticky="w")
self.buttonRemoveRestriction.grid(column=1, row=0, pady=5, padx=10, sticky="w")
self.textResultSequence.grid(row=1, column=0, columnspan=4, sticky="wens")
self.buttonSaveResult.grid(row=2, column=3, pady=5, sticky="e")
self.frameResultSequence.columnconfigure(2, weight=1)
self.frameResultSequence.rowconfigure(1, weight=1)
self.textResultSequence.frame.columnconfigure(1, weight=1)
self.textResultSequence.frame.rowconfigure(0, weight=1)
self.textSourceSeq.bind("<<Modified>>", self.actionSequenceModified)
self.textResultSequence.bind("<<Modified>>", self.actionSequenceModified)
# generate color tags for textboxes
for i in range(101):
# green for normal codons
(r, g, b) = colorsys.hsv_to_rgb(210 / 360, i / 100, 1.0)
colorHex = "#%02x%02x%02x" % (int(r * 255), int(g * 255), int(b * 255))
self.textSourceSeq.tag_config("normal" + str(i), background=colorHex)
self.textResultSequence.tag_config("normal" + str(i), background=colorHex)
# red for codons with restriction sites
(r, g, b) = colorsys.hsv_to_rgb(5 / 360, i / 100, 1.0)
colorHex = "#%02x%02x%02x" % (int(r * 255), int(g * 255), int(b * 255))
self.textSourceSeq.tag_config("restrict" + str(i), background=colorHex)
self.textResultSequence.tag_config("restrict" + str(i), background=colorHex)
# Set (minimum + max) Window size
self.guiRoot.update()
self.guiRoot.minsize(self.guiRoot.winfo_width(), self.guiRoot.winfo_height())
self.buttonRestricionAdd.bind("<ButtonRelease>", self.reactToClick)
self.buttonRestricionDel.bind("<ButtonRelease>", self.actionRestrictionEnzymeDelete)
self.buttonSpeciesList.bind("<ButtonRelease>", self.actionEditSpeciesButton)
self.buttonSourceLoad.bind("<ButtonRelease>", self.actionLoadSequence)
self.buttonSaveResult.bind("<ButtonRelease>", self.actionSaveSequence)
# TEST
# self.listRestriction.insert("end", "EcoRI")
# self.listRestriction.insert("end", "BamHI")
#
# dummy event to manually trigger update
self.guiRoot.bind("<<Update>>", self.actionUpdate)
self.actionUpdate(None)
self.guiRoot.mainloop()
def actionRestrictionEnzymeDelete(self, event):
try:
selectedEnzyme = self.listRestriction.selection_get()
self.optimizer.restrictionEnzymeList.remove(selectedEnzyme)
self.guiRoot.event_generate("<<Update>>")
except tkinter.TclError:
# no selection
pass
def actionUpdate(self, event):
# print("update called")