python全屏,无控制台/边框 [英] python full screen without console/borders

查看:85
本文介绍了python全屏,无控制台/边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种创建全屏窗口而不显示控制台(或边框),并在按转义"键时退出全屏的方法.我试图将扩展名从"py"重命名为"pyw",但它没有隐藏侧边栏

那么有什么方法可以让我在没有工具栏(MacOS)的情况下使用全屏显示,并且键盘可以正常工作吗?

谢谢!

解决方案

关于屏幕分辨率,该如何操作:

从Tkinter导入

  *导入ttkdefscape(root):root.geometry("200x200")def fullscreen(root):宽度,高度= root.winfo_screenwidth(),root.winfo_screenheight()root.geometry(%dx%d + 0 + 0&"%(宽度,高度))主= Tk()宽度,高度= master.winfo_screenwidth(),master.winfo_screenheight()master.geometry(%dx%d + 0 + 0&"%(宽度,高度))master.bind(< Escape>",lambda a:escape(master))#添加此代码很有趣,当您按F1时,它将返回全屏.master.bind("F1",lambda b:全屏(master))master.mainloop() 

这是无国界的(取自此处):

 将tkinter导入为tk根= tk.Tk()root.attributes('-alpha',0.0)#用于图标#root.lower()root.iconify()窗口= tk.Toplevel(根)window.geometry("100x100")#任何大小window.overrideredirect(1)#删除边框#window.attributes('-topmost',1)#任何按钮等close = tk.Button(窗口,文本=关闭窗口",命令= lambda:root.destroy())close.pack(填充= tk.BOTH,展开= 1)window.mainloop() 

控制台的唯一解决方案是按照已阅读的文件格式将文件另存为.pyw.您也可以尝试使用 overrideredirect(1)覆盖Tk函数,但这会更加复杂.

希望这对您有帮助,Yahli.

I'm looking for a way to create a full screen window and not showing console (or the borders), and escape the full screen when 'escape' is pressed. I have tried to rename the extension from 'py' to 'pyw', but it didn't hide the side bar as some suggested.

Here is my code to maximize the window, but it doesn't hide the console:

def __init__(master): #I'm using tkinter for my GUI
    master = master
    width, height = master.winfo_screenwidth(), master.winfo_screenheight()
    master.geometry("%dx%d+0+0" % (width, height))

In addition, I need to use the script on both Mac and Windows, are they working differently if I need to hide the console?

I have tried overrideredirect(True), but it doesn't allow me to use keyboard, which is required for my task. I also tried wm_attributes('-fullscreen', True) , but it doesn't create exactly full screen, there's empty place at the top where the Mac Taskbar existed.

So is there any way that allows me use full screen without the toolbar (MacOS), and the keyboard works?

Thanks!

解决方案

How about this for the screen resolution:

from Tkinter import *
import ttk

def escape(root):
        root.geometry("200x200")

def fullscreen(root):
        width, height = root.winfo_screenwidth(), root.winfo_screenheight()
        root.geometry("%dx%d+0+0" % (width, height))
        
master = Tk()
width, height = master.winfo_screenwidth(), master.winfo_screenheight()
master.geometry("%dx%d+0+0" % (width, height))
master.bind("<Escape>", lambda a :escape(master))
#Added this for fun, when you'll press F1 it will return to a full screen.
master.bind("<F1>", lambda b: fullscreen(master))
master.mainloop()

And this for no border (taken from here):

import tkinter as tk
root = tk.Tk()
root.attributes('-alpha', 0.0) #For icon
#root.lower()
root.iconify()
window = tk.Toplevel(root)
window.geometry("100x100") #Whatever size
window.overrideredirect(1) #Remove border
#window.attributes('-topmost', 1)
#Whatever buttons, etc 
close = tk.Button(window, text = "Close Window", command = lambda: root.destroy())
close.pack(fill = tk.BOTH, expand = 1)
window.mainloop()

The only solution for the console is to save the file as .pyw as you've already read. You can also try to override the Tk functions using overrideredirect(1) but that would be more complicated.

Hopefully this will help you, Yahli.

这篇关于python全屏,无控制台/边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆