Python Forum
strange python3 issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: strange python3 issue (/thread-12659.html)



strange python3 issue - tony1812 - Sep-06-2018

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.
# 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()



RE: strange python3 issue - Larz60+ - Sep-06-2018

on canvas1.py, you specify the size of the canvas, size 200 x 100:
w = Canvas(master, width=200, height=100)
on window_class.py, you are placing everything on the root window, so it has size 640 x 480