本文整理汇总了Python中Tkinter.Tk.focus_set方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.focus_set方法的具体用法?Python Tk.focus_set怎么用?Python Tk.focus_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Tk
的用法示例。
在下文中一共展示了Tk.focus_set方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: failure
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def failure(reason, cur_dir):
"""
Displays a "submission failure" picture and emails
a bug report to maintenance.
"""
bugmail = {"email": "[email protected]"}
send_email(bugmail, "QR Code Submission Failure", reason, None)
root = Tk()
root.focus_set()
# Get the size of the screen and place the splash screen in the center
gif = Image.open(str(cur_dir) + '/Images/Failure.gif')
width = gif.size[0]
height = gif.size[1]
flog = (root.winfo_screenwidth()/2-width/2)
blog = (root.winfo_screenheight()/2-height/2)
root.overrideredirect(1)
root.geometry('%dx%d+%d+%d' % (width*1, height + 44, flog, blog))
# Pack a canvas into the top level window.
# This will be used to place the image
failure_canvas = Canvas(root)
failure_canvas.pack(fill = "both", expand = True)
# Open the image
imgtk = PhotoImage(gif)
# Get the top level window size
# Need a call to update first, or else size is wrong
root.update()
cwidth = root.winfo_width()
cheight = root.winfo_height()
# create the image on the canvas
failure_canvas.create_image(cwidth/2, cheight/2.24, image=imgtk)
Button(root, text = str(
reason), width = 50, height = 2, command = root.destroy).pack()
root.after(5000, root.destroy)
root.mainloop()
示例2: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def main():
root = Tk()
# w, h = root.winfo_screenwidth(), root.winfo_screenheight()
w, h = 960, 540
# get value from arduino
# ser = serial.Serial('/dev/tty.usbserial', 9600)
pos = 0
root.overrideredirect(1)
root.focus_set()
root.bind("<Escape>", lambda e: e.widget.quit())
root.geometry("%dx%d+300+300" % (w, h))
canvas = Canvas(root, width=w, height=h, background="black")
rect0 = canvas.create_rectangle(w/2-75, h/2-20, w/2+75, h/2+20, fill="#05f", outline="#05f")
rect1 = canvas.create_rectangle(w/2-20, h/2-75, w/2+20, h/2+75, fill="#05f", outline="#05f")
canvas.pack()
while (True):
# gets angle and moves accordingly
# pos = ser.readline()
canvas.move(rect0, 1, 0)
canvas.move(rect1, 1, 0)
root.update()
root.after(30)
app = App(root)
time.sleep(0.5)
root.mainloop()
示例3: expired
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def expired(cur_dir, amount):
"""
Displays a "deadline expired" picture
"""
root = Tk()
root.focus_set()
# Get the size of the screen and place the splash screen in the center
img = Image.open(str(cur_dir) + '/Images/Expired.gif')
width = img.size[0]
height = img.size[1]
flog = root.winfo_screenwidth()/2-width/2
blog = root.winfo_screenheight()/2-height/2
root.overrideredirect(True)
root.geometry('%dx%d+%d+%d' % (width*1, height + 44, flog, blog))
# Pack a canvas into the top level window.
# This will be used to place the image
expired_canvas = Canvas(root)
expired_canvas.pack(fill="both", expand=True)
# Open the image
imgtk = PhotoImage(img)
# Get the top level window size
# Need a call to update first, or else size is wrong
root.update()
cwidth = root.winfo_width()
cheight = root.winfo_height()
# create the image on the canvas
expired_canvas.create_image(cwidth/2, cheight/2.1, image=imgtk)
Button(root, text='Deadline Expired by ' + str(amount
) + '. Assignment Submitted, time '\
'noted', width=80, height=2, command=root.destroy).pack()
root.after(5000, root.destroy)
root.mainloop()
示例4: success
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def success(cur_dir):
"""
Displays a "successful submission" picture
"""
root = Tk()
root.focus_set()
# Get the size of the screen and place the splash screen in the center
img = Image.open(str(cur_dir) + '/Images/Success.gif')
width = img.size[0]
height = img.size[1]
flog = (root.winfo_screenwidth()/2-width/2)
blog = (root.winfo_screenheight()/2-height/2)
root.overrideredirect(1)
root.geometry('%dx%d+%d+%d' % (width, height, flog, blog))
# Pack a canvas into the top level window.
# This will be used to place the image
success_canvas = Canvas(root)
success_canvas.pack(fill = "both", expand = True)
# Open the image
imgtk = PhotoImage(img)
# Get the top level window size
# Need a call to update first, or else size is wrong
root.update()
cwidth = root.winfo_width()
cheight = root.winfo_height()
# create the image on the canvas
success_canvas.create_image(cwidth/2, cheight/2, image = imgtk)
root.after(4000, root.destroy)
root.mainloop()
示例5: _test
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def _test():
import sys
from Tkinter import Tk
root = Tk()
root.configure(bd=0, bg="yellow")
root.focus_set()
sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
sc.frame.pack(expand=1, fill="both")
item = make_objecttreeitem("sys", sys)
node = TreeNode(sc.canvas, None, item)
node.update()
root.mainloop()
示例6: _object_browser
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def _object_browser(parent):
import sys
from Tkinter import Tk
root = Tk()
root.title("Test ObjectBrowser")
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
root.geometry("+%d+%d"%(x, y + 150))
root.configure(bd=0, bg="yellow")
root.focus_set()
sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
sc.frame.pack(expand=1, fill="both")
item = make_objecttreeitem("sys", sys)
node = TreeNode(sc.canvas, None, item)
node.update()
root.mainloop()
示例7: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def main():
"""Set up the stopwatch and the buttons/keyboard shortcuts to control it"""
root = Tk()
# Add stopwatch frame
stopwatch = StopWatch(root)
stopwatch.pack(side=TOP)
# Add buttons
Button(root, text='Start/Stop',
command=stopwatch.start_stop, takefocus=False).pack(side=LEFT)
Button(root, text='Reset',
command=stopwatch.reset, takefocus=False).pack(side=LEFT)
Button(root, text='Quit',
command=root.quit, takefocus=False).pack(side=LEFT)
# Add keyboard shurtcuts
root.bind("<space>", lambda x: stopwatch.start_stop())
root.bind("<BackSpace>", lambda x: stopwatch.reset())
root.bind("<Escape>", lambda x: root.quit())
root.focus_set()
root.mainloop()
示例8: PiPresents
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
#.........这里部分代码省略.........
if self.options['screensize'] =='':
self.screen_width = self.root.winfo_screenwidth()
self.screen_height = self.root.winfo_screenheight()
else:
reason,message,self.screen_width,self.screen_height=self.parse_screen(self.options['screensize'])
if reason =='error':
self.mon.err(self,message)
self.end('error',message)
self.mon.log(self, 'forced screen dimensions (--screensize) are ' + str(self.screen_width) + ' x ' + str(self.screen_height) + ' pixels')
# set window dimensions and decorations
if self.options['fullscreen'] is False:
self.window_width=int(self.root.winfo_screenwidth()*self.nonfull_window_width)
self.window_height=int(self.root.winfo_screenheight()*self.nonfull_window_height)
self.window_x=self.nonfull_window_x
self.window_y=self.nonfull_window_y
self.root.geometry("%dx%d%+d%+d" % (self.window_width,self.window_height,self.window_x,self.window_y))
else:
self.window_width=self.screen_width
self.window_height=self.screen_height
self.root.attributes('-fullscreen', True)
os.system('unclutter &')
self.window_x=0
self.window_y=0
self.root.geometry("%dx%d%+d%+d" % (self.window_width,self.window_height,self.window_x,self.window_y))
self.root.attributes('-zoomed','1')
# canvas cover the whole screen whatever the size of the window.
self.canvas_height=self.screen_height
self.canvas_width=self.screen_width
# make sure focus is set.
self.root.focus_set()
# define response to main window closing.
self.root.protocol ("WM_DELETE_WINDOW", self.handle_user_abort)
# setup a canvas onto which will be drawn the images or text
self.canvas = Canvas(self.root, bg=self.starter_show['background-colour'])
if self.options['fullscreen'] is True:
self.canvas.config(height=self.canvas_height,
width=self.canvas_width,
highlightthickness=0)
else:
self.canvas.config(height=self.canvas_height,
width=self.canvas_width,
highlightthickness=1,
highlightcolor='yellow')
self.canvas.place(x=0,y=0)
# self.canvas.config(bg='black')
self.canvas.focus_set()
# ****************************************
# INITIALISE THE TOUCHSCREEN DRIVER
# ****************************************
# each driver takes a set of inputs, binds them to symboic names
# and sets up a callback which returns the symbolic name when an input event occurs
self.sr=ScreenDriver()
示例9: start
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
def start():
""" Calaculates several values for the game's run."""
global canvas, mainChar, root, i, k, bob, Link, bill, f, g, enemy
user32 = ctypes.windll.user32 #renders size to fullscreen
w = int(user32.GetSystemMetrics(0))
h = int(user32.GetSystemMetrics(1))
f = int(w/40) # calculates how many tiles needed
g = int(h/40)
print w
root = Tk()
root.title("Transparency")
frame = Frame(root)
canvas = Canvas(frame, bg="black", width=w, height=h)
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
print w, h
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
root.focus_set() # <-- move focus to this widget
root.bind("<Escape>", quitApp) # All root bindings
root.bind("w", moveUp)
root.bind("s", moveDown)
root.bind("a", moveLeft)
root.bind("d", moveRight)
#root.bind("h", healthPotion)
root.bind("<space>", useItem)
root.bind("b", bossSpawn)
canvas.pack()
photoimage = ImageTk.PhotoImage(Image.open("dungeonTile.jpg"))
mainChar = ImageTk.PhotoImage(Image.open("CobaltKnight.png"))
enemy = ImageTk.PhotoImage(Image.open("LobsterRoach.png"))
im = Image.open("Karel.png")
print im.mode
x = 0
y = 0
print bill, "bill"
if bill == 0:
for i in range(f+1):
for k in range(g+1):
canvas.create_image(i*40, k*40, image=photoimage)
bill = 1
mainSpawn() #spawns main
mobSpawn(canvas,enemy) #spawns mobs
#bob = Label(canvas,width=w,height=h, text = "health", fg = 'red', font = ('Times', 30, 'bold'), anchor = 'nw')
#bob.pack()
bob = canvas.create_text(40,40, text = "bob", fill = "red", font = ('Times', 30, 'bold'), anchor = 'nw')
bar = "health " + str(Link.getHealth()) + "/" + str(Link.getMaxHealth())
canvas.itemconfig(bob, text=bar)
canvas.create_rectangle(w-120, 40 , w-40, 120, fill='black', outline = 'white')
canvas.create_rectangle(w-240, 40 , w-160, 120, fill='black', outline = 'white')
#createInterface(bob,canvas,i,k,Link.getHealth(),Link.getMaxHealth()) #creates user interface
#bob.pack()
frame.pack()
print "music"
#canvas.create_text(i,k, text = "health", fill = 'red', font = ('Times', 30, 'bold'), anchor = 'nw')
#f= wave.open( 'Naruto-Breakdown.wav', 'rb' )
#sampleRate= f.getframerate()
#channels= f.getnchannels()
#format = sound.AFMT_S16_LE
#snd= sound.Output( sampleRate, channels, format )
#s= f.readframes( 300000 )
#snd.play( s )
#while snd.isPlaying(): time.sleep( 0.05 )
#canvas.pack()
root.mainloop()
示例10: PiPresents
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
#.........这里部分代码省略.........
if self.options['screensize'] =='':
self.screen_width = self.root.winfo_screenwidth()
self.screen_height = self.root.winfo_screenheight()
else:
reason,message,self.screen_width,self.screen_height=self.parse_screen(self.options['screensize'])
if reason =='error':
self.mon.err(self,message)
self.end('error',message)
self.mon.log(self, 'commanded screen dimensions are ' + str(self.screen_width) + ' x ' + str(self.screen_height) + ' pixcels')
# set window dimensions and decorations
if self.options['fullscreen'] is False:
self.window_width=int(self.root.winfo_screenwidth()*self.nonfull_window_width)
self.window_height=int(self.root.winfo_screenheight()*self.nonfull_window_height)
self.window_x=self.nonfull_window_x
self.window_y=self.nonfull_window_y
self.root.geometry("%dx%d%+d%+d" % (self.window_width,self.window_height,self.window_x,self.window_y))
else:
self.window_width=self.screen_width
self.window_height=self.screen_height
self.root.attributes('-fullscreen', True)
os.system('unclutter 1>&- 2>&- &') # Suppress 'someone created a subwindow' complaints from unclutter
self.window_x=0
self.window_y=0
self.root.geometry("%dx%d%+d%+d" % (self.window_width,self.window_height,self.window_x,self.window_y))
self.root.attributes('-zoomed','1')
# canvs cover the whole screen whatever the size of the window.
self.canvas_height=self.screen_height
self.canvas_width=self.screen_width
# make sure focus is set.
self.root.focus_set()
# define response to main window closing.
self.root.protocol ("WM_DELETE_WINDOW", self.handle_user_abort)
# setup a canvas onto which will be drawn the images or text
self.canvas = Canvas(self.root, bg=self.pp_background)
if self.options['fullscreen'] is True:
self.canvas.config(height=self.canvas_height,
width=self.canvas_width,
highlightthickness=0)
else:
self.canvas.config(height=self.canvas_height,
width=self.canvas_width,
highlightthickness=1,
highlightcolor='yellow')
self.canvas.place(x=0,y=0)
# self.canvas.config(bg='black')
self.canvas.focus_set()
# ****************************************
# INITIALISE THE INPUT DRIVERS
# ****************************************
# each driver takes a set of inputs, binds them to symboic names
# and sets up a callback which returns the symbolic name when an input event occurs/
# use keyboard driver to bind keys to symbolic names and to set up callback
示例11: __init__
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
class GUIHandler:
screenwidth = 0
screenheight = 0
windowwidth = 0
windowheight = 0
## Initializes the GUI setup of the program.
#
def __init__(self,game):
assert type(game) is Game
self.root = Tk()
self.root.title('SET')
self.root.resizable(0,0)
self.root.withdraw()
GUIHandler.screenwidth = self.root.winfo_screenwidth()
GUIHandler.screenheight = self.root.winfo_screenheight()
if GUIHandler.screenwidth < 1024 or GUIHandler.screenheight < 768:
showerror("Resolution Error","Your screen's resolution is likely not the best choice to run this game. Minimum resolution for this game is at least 1024x768.")
raise ResolutionError(GUIHandler.screenwidth,GUIHandler.screenheight)
GUIHandler.windowwidth = GUIHandler.screenwidth // 3
GUIHandler.windowheight = GUIHandler.screenheight // 1.5
self.buttonField = None
self.checkButtonField = None
self.Game = game
self.Field = game.field
assert self.Game
assert self.Field
self.root.geometry('%dx%d+%d+%d' % (GUIHandler.windowwidth,
GUIHandler.windowheight,
self.root.winfo_screenwidth()/8,
self.root.winfo_screenheight()/8))
menu = Menu(self.root)
gamemenu = Menu(menu,tearoff=0)
gamemenu.add_command(label='New Game',command=lambda:self.startNewGame(),accelerator="F2")
gamemenu.add_command(label='Leaderboards',command=lambda:showinfo("Not implemented","Feature not implemented...yet."))
gamemenu.add_command(label='Exit',command=lambda:self.root.destroy(),accelerator="Alt-F4")
menu.add_cascade(label='Game',menu=gamemenu)
settingmenu = Menu(menu,tearoff=0)
gamedifficulty = Menu(settingmenu,tearoff=0)
gamedifficulty.add_radiobutton(label='Beginner',command=lambda :self.changeGameDifficulty(Difficulty.BEGINNER),accelerator="B")
gamedifficulty.add_radiobutton(label='Novice',command=lambda :self.changeGameDifficulty(Difficulty.NOVICE),accelerator="N")
gamedifficulty.add_radiobutton(label='Advanced',command=lambda :self.changeGameDifficulty(Difficulty.ADVANCED),accelerator="A")
settingmenu.add_cascade(label='Game Difficulty',menu=gamedifficulty)
timedmode = Menu(settingmenu,tearoff=0)
timedmode.add_radiobutton(label='On',command=lambda:showinfo("Not implemented","Feature not implemented...yet."))
timedmode.add_radiobutton(label='Off',command=lambda:showinfo("Not implemented","Feature not implemented...yet."))
settingmenu.add_cascade(label='Timed Mode',menu=timedmode)
timeddifficulty = Menu(settingmenu,tearoff=0)
timeddifficulty.add_radiobutton(label='Easy',accelerator="E")
timeddifficulty.add_radiobutton(label='Medium',accelerator="M")
timeddifficulty.add_radiobutton(label='Hard',accelerator="H")
settingmenu.add_cascade(label='Timed Difficulty',menu=timeddifficulty)
menu.add_cascade(label='Settings',menu=settingmenu)
helpmenu = Menu(menu,tearoff=0)
helpmenu.add_command(label='About SET',command=lambda:showinfo("Not implemented","Feature not implemented...yet."))
menu.add_cascade(label='Help',menu=helpmenu)
self.root.config(menu=menu)
self.root.bind('<F2>',lambda e:gamemenu.invoke(0))
self.root.bind('L',lambda e:gamemenu.invoke(1))
self.root.bind('<Alt-F4>',lambda e:gamemenu.invoke(2))
self.root.bind('b',lambda e:gamedifficulty.invoke(Difficulty.BEGINNER))
self.root.bind('n',lambda e:gamedifficulty.invoke(Difficulty.NOVICE))
self.root.bind('a',lambda e:gamedifficulty.invoke(Difficulty.ADVANCED))
self.remainderLabel = Label(self.root,text="There are %d set(s) remaining on the board." % self.Game.numSetsRemaining(),bg="white",relief=Tkinter.RAISED,font=('Helvetica',12))
self.remainderLabel.place(x=(GUIHandler.windowwidth-self.remainderLabel.winfo_reqwidth())//2,y=3*GUIHandler.windowheight//4)
timer = Label(self.root,text="Untimed Mode",bg="green",relief=Tkinter.RAISED,font=('Helvetica',12))
timer.place(x=(GUIHandler.windowwidth-timer.winfo_reqwidth())//2,y=3*GUIHandler.windowheight//4.5)
hintbutton = Button(text="Hint, please!",font=("Helvetica",12),command=lambda :self.getHint())
hintbutton.place(x=(GUIHandler.windowwidth-hintbutton.winfo_reqwidth())//2,y=3*GUIHandler.windowheight//3.5)
self.userSetsCreated = Toplevel(self.root)
self.userSetsHeight = 0
self.userSetsCreated.title("Sets Created")
self.userSetsCreated.geometry("%dx%d+%d+%d" % (Card.pixelWidth*3,
self.userSetsCreated.winfo_screenheight(),
self.root.winfo_pointerx()+self.userSetsCreated.winfo_reqwidth(),0))
self.userSetsCreated.protocol("WM_DELETE_WINDOW",0)
self.userSetsCreated.resizable(0,0)
self.root.focus_set()
#.........这里部分代码省略.........
示例12:
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import focus_set [as 别名]
# XXX TO DO: