#๐Ÿ”’ How to code a button to open a start.py in the same window?

13 messages ยท Page 1 of 1 (latest)

untold horizon
#

This is the code for my button

What I have in my Main.py
from start.py import start_game_interface

def start_game():
start_game_interface(root)

myButton = Button(root,
text="Start", # Text on the button
bg="#666666", # Button color
fg="white", # Text color
font=("Freestyle Script", 25, "bold"), # Font must be on computer
bd=3, # The border of the button
width=button_width,
height=button_height, # Height of the button
cursor="hand2", # Mouse cursor on hover
command=start_game)
myButton.grid(row=1, column=0, pady=(20, 10))

What I have in my Start.py
def start_game_interface(root):
for widget in root.winfo_children():
widget.destroy()

When I try and run the code through the command center I am told , "ModuleNotFoundError: No module named 'start'". However, Main,py and Start.py are 100% in the same folder.

rough sunBOT
#

@untold horizon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

knotty crane
#

import start, not import start.py. The file extension is not part of the module name.

untold horizon
#

I also tried that, but it still says the same thing. Its what I tried first actually.

river locust
queen prairie
#

What I have in my Start.py
Start.py is capitalized, the module name would be case-sensitive iirc. Try renaming your file to start.py, and of course changing from start.py to from start

untold horizon
#

OML am stupid and embarrassed that I didn't look at the capitalization. Thank you.

queen prairie
#

lmao any time

#

close your question with !close

untold horizon
#

Thank you!

#

!close

rough sunBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.