本文整理汇总了Python中tkinter.Tk.focus_force方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.focus_force方法的具体用法?Python Tk.focus_force怎么用?Python Tk.focus_force使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Tk
的用法示例。
在下文中一共展示了Tk.focus_force方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: independentScreen
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [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
示例2: SelectDataFiles
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
def SelectDataFiles():
"""Select the files to compress into a JAM"""
# Draw (then withdraw) the root Tk window
logging.info("Drawing root Tk window")
root = Tk()
logging.info("Withdrawing root Tk window")
root.withdraw()
# Overwrite root display settings
logging.info("Overwrite root settings to basically hide it")
root.overrideredirect(True)
root.geometry('0x0+0+0')
# Show window again, lift it so it can recieve the focus
# Otherwise, it is behind the console window
root.deiconify()
root.lift()
root.focus_force()
# The files to be compressed
jam_files = filedialog.askdirectory(
parent=root,
title="Where are the extracted LEGO.JAM files located?"
)
if not jam_files:
root.destroy()
colors.text("\nCould not find a JAM archive to compress!",
color.FG_LIGHT_RED)
main()
# Compress the JAM
root.destroy()
BuildJAM(jam_files)
示例3: selecttheIsland
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
def selecttheIsland():
"""Manually select a LEGO Island installation if detection fails."""
# Draw (then withdraw) the root Tk window
root = Tk()
root.withdraw()
root.overrideredirect(True)
root.geometry('0x0+0+0')
root.deiconify()
root.lift()
root.focus_force()
# Select the exe
logging.info("Display file selection dialog for LEGO Island exe")
manualGamePath = filedialog.askopenfilename(
parent=root,
title="Select your LEGO Island Executable (LEGOISLE.EXE)",
defaultextension=".exe",
filetypes=[("Windows Executable", "*.exe")]
)
# The user clicked the cancel button
if not manualGamePath:
# Give focus back to console window
root.destroy()
logging.warning("User did not select a LEGO Island installation!")
print("\nCould not find a vaild LEGO Island installation!")
main()
# The user selected an installation
else:
try:
# Display exit message
logging.info("Display exit message")
print("\nSee ya later, Brickulator!")
logging.info("Run user-defined installation, located at {0}"
.format(manualGamePath))
subprocess.call([manualGamePath])
# Close app
logging.info("{0} is shutting down".format(appName))
raise SystemExit(0)
# TODO I guess this works?
except Exception:
logging.warning("User-defined LEGO Island installation did not work!")
print("\nCould not run {0} from {1}!".format(game, manualGamePath))
logging.info("Re-running manual installation process")
print("\nPlease select a new {0} installation".format(game))
time.sleep(2)
selecttheIsland()
示例4: __init__
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
def __init__(self, message, title='알림', callback=None, grab_focus = False):
tk=Tk()
tk.resizable(0, 0)
self.frame = Frame(tk, border=7)
self.frame.pack(expand='true')
self.frame.master.title(title)
Label(self.frame, text=message).pack(side='top', expand='true')
self.callback=callback
Button(self.frame, text="확인", command=self.onPress).pack(expand='true')
tk.focus_force()
if grab_focus:
tk.grab_set_global()
示例5: _exe_
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
def _exe_(self):
'''The actual execute code for doing command. Every exception it throws will
be thrown to execute to be a command runtime error. This error handling has
been delegated to the execute(). Outsider should not use this method for run
Developer needs to inheritance this method for the command to run
'''
self.camera.start_preview()
# TODO: let's change the scheme for the preview. That is using a Tkinter
# to receive the non ascii key to provide good avoidance
# One thing is that tkinter might not be available. So we need to
# include it before we can actually make it work.
root = Tk()
# bind the key here
self._bind_keys_(root)
# force the user to focus on the root controller
root.focus_force()
root.mainloop()
示例6: SelectJAMArchive
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
def SelectJAMArchive():
"""Select the JAM Archive to extract"""
# Draw (then withdraw) the root Tk window
logging.info("Drawing root Tk window")
root = Tk()
logging.info("Withdrawing root Tk window")
root.withdraw()
# Overwrite root display settings
logging.info("Overwrite root Tk window settings to hide it")
root.overrideredirect(True)
root.geometry('0x0+0+0')
# Show window again, lift it so it can receive the focus
# Otherwise, it is behind the console window
root.deiconify()
root.lift()
root.focus_force()
# Select the LEGO Racers installation
logging.info("Where is the JAM archive to be extracted located?")
jam_location = filedialog.askopenfilename(
parent=root,
title="Where is LEGO.JAM",
defaultextension=".JAM",
filetypes=[("LEGO.JAM", "*.JAM")]
)
if not jam_location:
root.destroy()
colors.text("\nCould not find a JAM archive to extract!",
color.FG_LIGHT_RED)
main()
# Extract the JAM
root.destroy()
ExtractJAM(jam_location)
示例7: SelectPiInstall
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
def SelectPiInstall():
"""Searches or asks for user's PatchIt! installation"""
# Used to detect if user needs to manually define an installation
found_install = False
# Path to check for PatchIt! on Windows x64
x64_path = os.path.join(os.path.expandvars("%ProgramFiles(x86)%"), "PatchIt")
# Path to check for PatchIt! on Windows x86
x86_path = os.path.join(os.path.expandvars("%ProgramFiles%"), "PatchIt")
# Perhaps the Updater is in the same place as PatchIt!.
# In that case, use a different method for finding the installation
same_path = os.path.join(os.path.dirname(app_folder), "Settings")
# The updater resides in the same location as PatchIt!
if os.path.exists(same_path):
# It's been found, no need for user to define it
found_install = True
# Write the installation to file
SavePiInstall(os.path.dirname(app_folder))
# If this is x64 Windows, look for PatchIt in Program Files (x86)
if os_bit:
if os.path.exists(os.path.join(x64_path, "PatchIt.exe")):
# It's been found, no need for user to define it
found_install = True
# Write the installation to file
SavePiInstall(x64_path)
# If this is x86 Windows, look for PatchIt in Program Files
else:
if os.path.exists(os.path.join(x86_path, "PatchIt.exe")):
# It's been found, no need for user to define it
found_install = True
# Write the installation to file
SavePiInstall(x86_path)
if not found_install:
print(
"""Could not find a valid PatchIt! installation!
Please select your PatchIt! installation."""
)
# Draw (then withdraw) the root Tk window
root = Tk()
root.withdraw()
# Overwrite root display settings
root.overrideredirect(True)
root.geometry("0x0+0+0")
# Show window again, lift it so it can receive the focus
# Otherwise, it is behind the console window
root.deiconify()
root.lift()
root.focus_force()
# Select PatchIt.exe
pi_path = filedialog.askopenfilename(
parent=root, title="Where is PatchIt.exe", defaultextension=".exe", filetypes=[("PatchIt.exe", "*.exe")]
)
# Give focus back to console window
root.destroy()
# Get the directory PatchIt! is in
pi_path = os.path.dirname(pi_path)
# The user clicked the cancel button
if pi_path:
# Write the installation to file
SavePiInstall(pi_path)
示例8: App
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
#.........这里部分代码省略.........
self.infoText.set("Error")
self.info.configure(text=self.infoText.get())
def set_canvas(self,master=None,height=500,width=500,bg="grey" ):
if master==None:
master=self.window
self.canvas = prgCanvas(master,height=height,width=width,bg=bg)
def nextprev(self,direction):
self.currentfileindex+=1 if abs(direction)==direction else -1
if self.currentfileindex<0:
self.currentfileindex = len(self.lst)-1
elif self.currentfileindex>len(self.lst)-1:
self.currentfileindex = 0
self.canvas.setdefault(reper=True)
self.infoText.set("Current file: "+self.lst[self.currentfileindex])
self.info.configure(text=self.infoText.get())
self.canvas.configure(self.lst[self.currentfileindex])
#рисуем
self.canvas.paint()
#здесь мы создаем группу
gr = list()
for item in self.canvas.field:
print(item[2][2])
if not (item[2][2] in gr):#выделяем уникальные данные
gr.append(item[2][2])
self.Filter.lst.delete(2,END)
for item in gr:
self.Filter.lst.insert(END,item)
def _changemashtab(self,event,dm):
self.canvas.mashtab*=dm
self.canvas.genfield()
def filter_selection(self):
name = self.Filter.lst.get(self.Filter.lst.curselection())
if name == "Hide All":
print("Hide All")
self.canvas.flagDescription = False
self.canvas.filter = None
self.canvas.genfield()
elif name =="Show All":
print("Show All")
self.canvas.flagDescription = True
self.canvas.filter = None
self.canvas.genfield()
else:
print("Other filter"+name)
self.canvas.flagDescription = True
#устанавливаем фильтр
self.canvas.configure(filter=lambda x: x==name)
#перерисовываем
self.canvas.paint()
def configure(self):
self.window.bind("<Key-Right>",lambda event:self.canvas.move(10,0))
self.window.bind("<Key-Left>",lambda event:self.canvas.move(-10,0))
self.window.bind("<Key-Down>",lambda event:self.canvas.move(0,10))
self.window.bind("<Key-Up>",lambda event:self.canvas.move(0,-10))
self.window.bind("<Key-plus>",lambda event:self._changemashtab(event,1.1))
self.window.bind("p",lambda event:self._changemashtab(event,1.1))
self.window.bind("<Key-minus>",lambda event:self._changemashtab(event,0.9))
self.window.bind("m",lambda event:self._changemashtab(event,0.9))
self.Filter.lst.bind("<<ListboxSelect>>", lambda event: self.filter_selection())
self.Filter.bind("<Leave>",lambda event: self.window.focus_force())
self.nextButton.configure(command=lambda:self.nextprev(1))
self.prevButton.configure(command=lambda:self.nextprev(-1))
self.window.bind("<Key-Prior>",lambda event:self.nextprev(-1)) #Page Up
self.window.bind("<Key-Next>",lambda event:self.nextprev(1)) #Page Down
def startloop(self):
self.leftframe.pack (side=LEFT,expand="y",fill="both")
# self.leftframe.pack ()
print("leftframe")
self.canvas.pack (expand="y",fill="both")
self.canvas.canvas.pack ()
self.canvas.configure(file=self.lst[self.currentfileindex])
self.canvas.paint()
self.bottomleftframe.pack()
self.nextButton.pack (side=RIGHT)
self.prevButton.pack (side=LEFT)
self.rightframe.pack(side=RIGHT,expand="y",fill="y")
# self.rightframe.pack()
print("rightframe")
self.info.pack (side=TOP,fill=X,expand=Y)
self.listfiles.pack (side=TOP,fill=BOTH,expand=Y)
self.Filter.pack (side=TOP, fill=BOTH, expand=Y)
self.helpText.pack (side=BOTTOM)
self.window.mainloop()
示例9: LRWriteSettings
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus_force [as 别名]
def LRWriteSettings():
"""Write PatchIt! LEGO Racers settings"""
# Draw (then withdraw) the root Tk window
logging.info("Drawing root Tk window")
root = Tk()
logging.info("Withdrawing root Tk window")
root.withdraw()
# Overwrite root display settings
logging.info("Overwrite root Tk window settings to hide it")
root.overrideredirect(True)
root.geometry('0x0+0+0')
# Show window again, lift it so it can receive the focus
# Otherwise, it is behind the console window
root.deiconify()
root.lift()
root.focus_force()
# Select the LEGO Racers installation
logging.info("Display folder dialog for LEGO Racers installation")
new_racers_game = filedialog.askopenfilename(
parent=root,
title="Where is LEGORacers.exe",
defaultextension=".exe",
filetypes=[("LEGORacers.exe", "*.exe")]
)
# Get the directory the Exe is in
new_racers_game = os.path.dirname(new_racers_game)
# The user clicked the cancel button
if not new_racers_game:
# Give focus back to console window
logging.info("Give focus back to console window")
root.destroy()
# Go back to the main menu
logging.warning("User did not select a new LEGO Racers installation!")
PatchIt.main()
# The user selected a folder
else:
logging.info("User selected a new LEGO Racers installation at {0}"
.format(new_racers_game))
# Give focus back to console window
logging.info("Give focus back to console window")
root.destroy()
# Create Settings directory if it does not exist
logging.info("Creating Settings directory")
if not os.path.exists(const.settings_fol):
os.mkdir(const.settings_fol)
# Write settings, using UTF-8 encoding
logging.info("Open 'Racers.cfg' for writing using UTF-8-NOBOM encoding")
with open(os.path.join(const.settings_fol, const.LR_settings),
"wt", encoding="utf-8") as racers_file:
# As partially defined in PatchIt! Dev-log #6
# (http://wp.me/p1V5ge-yB)
logging.info("Write line telling what program this file belongs to")
racers_file.write("// PatchIt! V1.1.x LEGO Racers Settings\n")
# Write brief comment explaining what the number means
# "Ensures the first-run process will be skipped next time"
logging.info("Write brief comment explaining what the number means")
racers_file.write("# Ensures the first-run process will be skipped next time\n")
logging.info("Write '1' to line 3 to skip first-run next time")
racers_file.write("1\n")
# Run check for 1999 or 2001 version of Racers
logging.info("Run LRVerCheck() to find the version of LEGO Racers")
LRVer = LRVerCheck(new_racers_game)
logging.info("Write brief comment telling what version this is")
racers_file.write("# Your version of LEGO Racers\n")
logging.info("Write game version to fifth line")
racers_file.write(LRVer)
logging.info("Write brief comment explaining the folder path")
racers_file.write("\n# Your LEGO Racers installation path\n")
logging.info("Write new installation path to seventh line")
racers_file.write(new_racers_game)
# Log closure of file (although the with handle did it for us)
logging.info("Closing Racers.cfg")
logging.info("Proceeding to read LEGO Racers Settings")
LRReadSettings()