![](/img/trans.png)
[英]I can't resize the scrollbar in python tkinter canvas (it is too small, I set the width option, but it did not work)
[英]How can I set the width of a canvas to the width of the screen in Python Tkinter?
我在tkinter
中有一个需要跨越整个屏幕宽度的画布,但无法让它工作。
我试图使屏幕宽度成为一个变量并将其作为类中的参数传递但向我抛出一个错误,我试图将root.winfo_screenwidth
设置为self.winfo_screenwidth
但它只是向我抛出一个错误,我看着www 的答案,但我看到的最接近的是如何将root
设置为屏幕大小。
这是我的代码:
import tkinter as tk
class Window(tk.Frame):
def __init__(self, master, **kwargs):
super().__init__(master, **kwargs)
canvas = tk.Canvas(self, width="", height=100) #How to set the width to the screen width?
canvas.config(bg="#505050")
canvas.pack()
def mainloop_scw():
root = tk.Tk()
root.title("Editor - Adventure")
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
root.geometry("%sx%s" %(screenwidth, screenheight))
root.config(bg="#303030")
app = Window(root)
app.config(bg="#303030")
app.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
root.mainloop()
if __name__ == "__main__":
mainloop_scw()
有谁知道如何将canvas
宽度设置为screenwidth
?
您不需要显式设置画布的宽度。 pack
具有可用于强制画布占据整个屏幕宽度的选项。
canvas.pack(fill="x")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.