Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strange python3 issue
#1
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()
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange issue with tkcalendar dady 1 921 Apr-04-2023, 08:19 PM
Last Post: dady
  Type conversion issue while using Descriptor in Python3 mailnsuresh 1 2,815 May-07-2020, 12:26 PM
Last Post: deanhystad
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,820 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  Strange issue Irhcsa 1 1,869 Oct-03-2018, 08:17 PM
Last Post: nilamo
  Issue python3.6 while inheriting telnet library sourabhjaiswal92 4 4,028 May-09-2018, 05:20 AM
Last Post: sourabhjaiswal92
  Code issue with time remaining loop. Python3 deboerdn2000 11 8,704 May-04-2017, 04:53 PM
Last Post: deboerdn2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020