Sep-06-2018, 12:07 AM
Hello, I am learning tkinter, in the process, I run into a strange problem. I have two python3 simple scripts, one is named window_class.py the other named canvas1.py. The problem is I set up the window size-640x480 on window_class.py it comes out the correct window siz but on canvas1.py it comes out a small window. Below I have the two files, I commited out the unrelated parts, so they are practically the same code, but why would they come out differently? Thanks.
I have python3.7.0.
I have python3.7.0.
# canvas1.py
from tkinter import Tk, Label, Button
root = Tk()
root.geometry=('640x480')
'''
w = Canvas(master, width=200, height=100)
w.pack()
w.create_rectangle(50, 20, 150, 80, fill="#476042")
w.create_rectangle(65, 35, 135, 65, fill="yellow")
w.create_line(0, 0, 50, 20, fill="#476042", width=3)
w.create_line(0, 100, 50, 80, fill="#476042", width=3)
w.create_line(150,20, 200, 0, fill="#476042", width=3)
w.create_line(150, 80, 200, 100, fill="#476042", width=3)
'''
root.mainloop()#window_class.py
from tkinter import Tk, Label, Button
'''
class MyGUI:
def __init__(self, master):
self.master = master
master.title("Our GUI in a class")
self.label = Label(master, text="This is our GUI in a class!")
self.label.pack()
self.greet_button = Button(master, text="Greet", command=self.greet)
self.greet_button.pack()
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
def greet(self):
print("Greetings!")
'''
root = Tk()
root.geometry('640x480')
#my_gui = MyGUI(root)
root.mainloop()
