【发布时间】:2019-09-01 09:43:00
【问题描述】:
我在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?
【问题讨论】:
标签: python canvas tkinter screen