Python 我无法使画布按我所希望的方式工作
我已经为我正在进行的设计创建了一个GUI,画布正在一个新窗口中弹出。我想让它出现在按钮下面Python 我无法使画布按我所希望的方式工作,python,tkinter,tkinter-canvas,Python,Tkinter,Tkinter Canvas,我已经为我正在进行的设计创建了一个GUI,画布正在一个新窗口中弹出。我想让它出现在按钮下面 __author__ = 'Isaac Alderton' __authorEmail__ = 'Isaacary92@gmail.com' from Tkinter import * class Application(Frame): """ My smart board application""" def __init__(self, master): Frame.__init__(s
__author__ = 'Isaac Alderton'
__authorEmail__ = 'Isaacary92@gmail.com'
from Tkinter import *
class Application(Frame):
""" My smart board application"""
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
#Button1
#buttons ment to span across the width of the page
#needs linking to google calander
self.button1 = Button(self, text = " Calandar ")
self.button1.grid(row=1,column = 1)
#button2
self.button2 = Button(self, text = " weather ")
self.button2.grid(row=1,column = 2)
#button3
#defult home menu in the future user sets a new home
self.button3 = Button(self, text = " Whiteboard ")
self.button3.grid(row=1,column = 3)
#button4
self.button4 = Button(self, text = " Internet ")
self.button4.grid(row=1,column = 4)
#button5
self.button5 = Button(self, text = " Settings ")
self.button5.grid(row=1,column = 5)
#def settings():
#pop up window where the settings options have wifi screen brightness sleep options
#and also account settings
#One day also ui changes so color themes etc
#Canvas
#canvas ment to be part of whiteboard screen not a "pop-up"
#canvas is ment to fill the whole page
def xy(event):
global lastx, lasty
lastx, lasty = event.x, event.y
def addLine(event):
global lastx, lasty
canvas.create_line((lastx, lasty, event.x, event.y))
lastx, lasty = event.x, event.y
root = Tk()
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
canvas = Canvas(root)
canvas.grid(column=5, row=4,)
canvas.bind("<Button-1>", xy)
canvas.bind("<B1-Motion>", addLine)
#endof canvas
root = Tk()
root.title("Smartboard")
#Geometry is ment to fit device????
root.geometry("530x500")
app = Application(root)
root.mainloop()
# Copyright {2015} {Isaac Alderton}
您的问题是代码的最后一部分是:
root = Tk()
#...
canvas = Canvas(root)
#...
#endof canvas
root = Tk()
#...
app = Application(root)
您将创建一个窗口,添加画布,然后创建一个新窗口,并将框架添加到该新窗口。如果将第二个root=Tk注释掉,则效果良好。将布局调整为:
__author__ = 'Isaac Alderton'
__authorEmail__ = 'Isaacary92@gmail.com'
from Tkinter import *
class Application(Frame):
""" My smart board application"""
def __init__(self, master):
Frame.__init__(self, master)
self.grid(column=0, row=0, sticky="ew")
self.create_widgets()
for i in range(5):
self.columnconfigure(i, weight=1)
self.rowconfigure(0, weight=1)
def create_widgets(self):
#Button1
#buttons ment to span across the width of the page
#needs linking to google calander
self.button1 = Button(self, text = " Calandar ")
self.button1.grid(row=0, column = 0, sticky="ew")
#button2
self.button2 = Button(self, text = " weather ")
self.button2.grid(row=0, column = 1, sticky="ew")
#button3
#defult home menu in the future user sets a new home
self.button3 = Button(self, text = " Whiteboard ")
self.button3.grid(row=0, column = 2, sticky="ew")
#button4
self.button4 = Button(self, text = " Internet ")
self.button4.grid(row=0, column = 3, sticky="ew")
#button5
self.button5 = Button(self, text = " Settings ")
self.button5.grid(row=0, column = 4, sticky="ew")
#def settings():
#pop up window where the settings options have wifi screen brightness sleep options
#and also account settings
#One day also ui changes so color themes etc
#Canvas
#canvas ment to be part of whiteboard screen not a "pop-up"
#canvas is ment to fill the whole page
def xy(event):
global lastx, lasty
lastx, lasty = event.x, event.y
def addLine(event):
global lastx, lasty
canvas.create_line((lastx, lasty, event.x, event.y))
lastx, lasty = event.x, event.y
root = Tk()
root.columnconfigure(0, weight=1)
root.rowconfigure(1, weight=1)
canvas = Canvas(root)
canvas.grid(column=0, row=1, sticky="nesw")
canvas.bind("<Button-1>", xy)
canvas.bind("<B1-Motion>", addLine)
#endof canvas
#root = Tk()
root.title("Smartboard")
#Geometry is ment to fit device????
root.geometry("530x500")
app = Application(root)
root.mainloop()
# Copyright {2015} {Isaac Alderton}
给出:
现在我的问题是,它不会听行或列,我需要顶部的文本框,它们是如何在画布出现在同一窗口之前的位置:/如果你运行断开的代码,它会告诉你布局应该如何……当我将画布更改为除列=0以外的任何内容时,它都不起作用……先生,你太神奇了: