本文整理汇总了Python中tkinter.Tk方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.Tk方法的具体用法?Python tkinter.Tk怎么用?Python tkinter.Tk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter
的用法示例。
在下文中一共展示了tkinter.Tk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def __init__(self, text="IPSUM DOLOREM", pos="BR"):
self.text = text
self.pos = pos
self.fg = "black"
self.bg = "#f1f2f2" # default transparent color
self.width = 0
self.height = 0
tk = tkinter.Tk()
self.label = tkinter.Label(tk, anchor="w")
self.label.config(font=("Consolas", 8))
self.label.master.overrideredirect(True)
self.label.master.lift()
self.label.master.wm_attributes("-topmost", True)
self.label.master.wm_attributes("-disabled", True)
self.label.master.wm_attributes("-transparentcolor", "#f1f2f3")
hWindow = pywintypes.HANDLE(int(self.label.master.frame(), 16))
exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | \
win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT
win32api.SetWindowLong(hWindow, win32con.GWL_EXSTYLE, exStyle)
self.label.pack()
self.update()
示例2: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def __init__(self):
root = tk.Tk()
# show no frame
root.overrideredirect(True)
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (self.width / 2)
y = (hs / 2) - (self.height / 2)
root.geometry('%dx%d+%d+%d' % (self.width, self.height, x, y))
image = tk.PhotoImage(file=self.image_file)
canvas = tk.Canvas(root, height=self.height, width=self.width, bg="brown")
canvas.create_image(self.width/2, self.height/2, image=image)
canvas.pack()
root.after(2500, root.destroy)
root.mainloop()
示例3: check_python_version
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def check_python_version():
"""Check if correct python version is run."""
if sys.hexversion < 0x03050200:
# We don't use .format() and print_function here just in case someone
# still has < 2.6 installed.
version_str = '.'.join(map(str, sys.version_info[:3]))
text = ("At least Python 3.5.2 is required to run qutebrowser, but " +
"it's running with " + version_str + ".\n")
if (Tk and # type: ignore[unreachable]
'--no-err-windows' not in sys.argv): # pragma: no cover
root = Tk()
root.withdraw()
messagebox.showerror("qutebrowser: Fatal error!", text)
else:
sys.stderr.write(text)
sys.stderr.flush()
sys.exit(1)
示例4: make
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def make():
global root
global app
global root_destroyed
global redetect_before_start
root = tk.Tk()
root_destroyed = False
root.protocol("WM_DELETE_WINDOW", close)
root.resizable(False, False)
if MAIN_ICON != None:
if os.path.splitext(MAIN_ICON)[1].lower() == ".gif":
root.call('wm', 'iconphoto', root._w, tk.PhotoImage(file=MAIN_ICON))
else:
root.iconbitmap(MAIN_ICON)
app = Main_Window(root)
app.raise_above_all()
app.after(100, app.connect_lp)
app.mainloop()
示例5: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.title('Tk Chat')
self.geometry('700x500')
self.menu = tk.Menu(self, bg="lightgrey", fg="black", tearoff=0)
self.friends_menu = tk.Menu(self.menu, fg="black", bg="lightgrey", tearoff=0)
self.friends_menu.add_command(label="Add Friend", command=self.show_add_friend_window)
self.avatar_menu = tk.Menu(self.menu, fg="black", bg="lightgrey", tearoff=0)
self.avatar_menu.add_command(label="Change Avatar", command=self.change_avatar)
self.menu.add_cascade(label="Friends", menu=self.friends_menu)
self.menu.add_cascade(label="Avatar", menu=self.avatar_menu)
self.requester = Requester()
self.show_login_screen()
示例6: generate_sub_menus
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def generate_sub_menus(self, sub_menu_items):
window_methods = [method_name for method_name in dir(self)
if callable(getattr(self, method_name))]
tkinter_methods = [method_name for method_name in dir(tk.Tk)
if callable(getattr(tk.Tk, method_name))]
my_methods = [method for method in set(window_methods) - set(tkinter_methods)]
my_methods = sorted(my_methods)
for item in sub_menu_items:
sub_menu = tk.Menu(self.menu, tearoff=0, bg=self.background, fg=self.foreground)
matching_methods = []
for method in my_methods:
if method.startswith(item):
matching_methods.append(method)
for match in matching_methods:
actual_method = getattr(self, match)
method_shortcut = actual_method.__doc__.strip()
friendly_name = ' '.join(match.split('_')[1:])
sub_menu.add_command(label=friendly_name.title(), command=actual_method, accelerator=method_shortcut)
self.menu.add_cascade(label=item.title(), menu=sub_menu)
self.all_menus.append(sub_menu)
示例7: app
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def app():
global root, sz, rz, rex0
root = tk.Tk()
root.resizable(height=False,width=True)
root.title(windowTitle)
root.minsize(width=250,height=0)
sz = FindZone("find",initialFind,initialText)
sz.fld.bind("<Button-1>",launchRefresh)
sz.fld.bind("<ButtonRelease-1>",launchRefresh)
sz.fld.bind("<B1-Motion>",launchRefresh)
sz.rexSel = re.compile("")
rz = ReplaceZone("repl",initialRepl,"")
rex0 = re.compile(r"(?<!\\)\\([0-9]+)")
root.bind_all("<Key>",launchRefresh)
launchRefresh(None)
root.mainloop()
示例8: ShowMol
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def ShowMol(mol, size=(300, 300), kekulize=True, wedgeBonds=True, title='RDKit Molecule', **kwargs):
""" Generates a picture of a molecule and displays it in a Tkinter window
"""
global tkRoot, tkLabel, tkPI
try:
import Tkinter
except ImportError:
import tkinter as Tkinter
try:
import ImageTk
except ImportError:
from PIL import ImageTk
img = MolToImage(mol, size, kekulize, wedgeBonds, **kwargs)
if not tkRoot:
tkRoot = Tkinter.Tk()
tkRoot.title(title)
tkPI = ImageTk.PhotoImage(img)
tkLabel = Tkinter.Label(tkRoot, image=tkPI)
tkLabel.place(x=0, y=0, width=img.size[0], height=img.size[1])
else:
tkPI.paste(img)
tkRoot.geometry('%dx%d' % (img.size))
示例9: ui
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def ui():
root = tkinter.Tk()
root.title('PDF和照片互转器') # 标题
root.resizable(width=False, height=False) # 防止大小调整
canvas = tkinter.Canvas(root, width=450, height=320, highlightthickness=0) # 创建画布
photo = tkinter.PhotoImage(file=file_zip_path + os.sep + 'pdf.png') # 获取背景图片的网络连接
canvas.create_image(225, 160, image=photo)
select_dir_button = tkinter.Button(root, text="选择照片文件夹", command=select_dir, bg='yellow') # 创建按钮
select_pdf_button = tkinter.Button(root, text="选择PDF文件", command=select_pdf, bg='green')
click_button = tkinter.Button(root, text="点击执行", command=start, bg='blue')
select_dir_button.pack() # 启动按钮
select_pdf_button.pack()
click_button.pack()
canvas.create_window(240, 120, width=100, height=30, window=select_dir_button) # 将按钮创建到画布
canvas.create_window(240, 190, width=100, height=30, window=select_pdf_button)
canvas.create_window(240, 260, width=100, height=30, window=click_button)
canvas.pack() # 启动画布
root.mainloop() # 主程序循环
示例10: check_pyqt
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def check_pyqt():
"""Check if PyQt core modules (QtCore/QtWidgets) are installed."""
for name in ['PyQt5.QtCore', 'PyQt5.QtWidgets']:
try:
importlib.import_module(name)
except ImportError as e:
text = _missing_str(name)
text = text.replace('<b>', '')
text = text.replace('</b>', '')
text = text.replace('<br />', '\n')
text = text.replace('%ERROR%', str(e))
if tkinter and '--no-err-windows' not in sys.argv:
root = tkinter.Tk()
root.withdraw()
tkinter.messagebox.showerror("qutebrowser: Fatal error!", text)
else:
print(text, file=sys.stderr)
if '--debug' in sys.argv or '--no-err-windows' in sys.argv:
print(file=sys.stderr)
traceback.print_exc()
sys.exit(1)
示例11: early_init
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def early_init(args):
"""Do all needed early initialization.
Note that it's vital the other earlyinit functions get called in the right
order!
Args:
args: The argparse namespace.
"""
# First we initialize the faulthandler as early as possible, so we
# theoretically could catch segfaults occurring later during earlyinit.
init_faulthandler()
# Here we check if QtCore is available, and if not, print a message to the
# console or via Tk.
check_pyqt()
# Init logging as early as possible
init_log(args)
# Now we can be sure QtCore is available, so we can print dialogs on
# errors, so people only using the GUI notice them as well.
check_libraries()
check_qt_version()
configure_pyqt()
check_ssl_support()
check_optimize_flag()
示例12: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def __init__(self):
self.root = tkinter.Tk()
self.root.title("Mandelbrot (Pyro multi CPU core version)")
canvas = tkinter.Canvas(self.root, width=res_x, height=res_y, bg="#000000")
canvas.pack()
self.img = tkinter.PhotoImage(width=res_x, height=res_y)
canvas.create_image((res_x/2, res_y/2), image=self.img, state="normal")
with locate_ns() as ns:
mandels = ns.yplookup(meta_any={"class:mandelbrot_calc_color"})
mandels = list(mandels.items())
print("{0} mandelbrot calculation servers found.".format(len(mandels)))
if not mandels:
raise ValueError("launch at least one mandelbrot calculation server before starting this")
self.mandels = [uri for _, (uri, meta) in mandels]
self.pool = futures.ThreadPoolExecutor(max_workers=len(self.mandels))
self.tasks = []
self.start_time = time.time()
for line in range(res_y):
self.tasks.append(self.calc_new_line(line))
self.root.after(100, self.draw_results)
tkinter.mainloop()
示例13: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def __init__(self,camera):
self.camera = camera
self.label_shape = 800,600
self.scale_length = 350
self.last_reticle_pos = (0,0)
self.root = tk.Tk()
self.root.protocol("WM_DELETE_WINDOW",self.stop)
self.zoom_step = .1
self.reset_zoom()
self.img = self.camera.read_image()[1]
self.on_resize()
self.convert_img()
self.create_window()
self.update_img()
self.start_histogram()
self.update_histogram()
self.refresh_rate = 1/50
self.low = 0
self.high = 255
self.t = time()
self.t_fps = self.t
self.go = True
#self.main()
示例14: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def __init__(self, labels, nb_digits, queue):
self.root = Tk()
self.root.title('Dashboard')
self.root.resizable(width=False, height=False)
self.first_column = labels
self.nb_digits = nb_digits
self.c2 = []
self.queue = queue
# Creating the first and second column. Second column will be updated.
for row_index, first_column in enumerate(self.first_column):
Label(self.root, text=first_column, borderwidth=15,
font=("Courier bold", 48)).grid(row=row_index, column=0)
self.c2.append(
Label(self.root, text='', borderwidth=15, font=("Courier bold", 48)))
self.c2[row_index].grid(row=row_index, column=1)
self.i = 0
while True:
self.update()
示例15: create_wf_gui
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Tk [as 别名]
def create_wf_gui():
""" Create a GUI with Tkinter to fill the workflow to run
Args:
cpacs_path (str): Path to the CPACS file
cpacs_out_path (str): Path to the output CPACS file
module_list (list): List of module to inclue in the GUI
"""
root = tk.Tk()
root.title('Workflow Creator')
root.geometry('475x490+400+100')
my_gui = WorkFlowGUI()
my_gui.mainloop()
disg = my_gui.Options
root.iconify() # Not super solution but only way to make it close on Mac
root.destroy()
return disg