Input Level Python












0














I developed a little to learn Python.

This one has a level editor. I would like users to have direct access to the level they have created by entering the corresponding number. No interface needs, just an input.

For now the game starts directly at level 1 with the self.level (1), I do not know where to put my input so that the 1 is replaced by the entered value.

Thank you in advance for the help you could provide!



Here is my code :



This method initializes some attributes: the ball, the bar...



def __init__(self, root):
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
self.pack()
self.timeContainer = self.create_text(self.screenWidth/2, self.screenHeight*4/5, text="00:00:00", fill="#bdc3c7", font=("Arial", 15), justify="center")
self.shield = self.create_rectangle(0, 0, 0, 0, width=0)
self.bar = self.create_rectangle(0, 0, 0, 0, fill="#7f8c8d", width=0)
self.ball = self.create_oval(0, 0, 0, 0, width=0)
self.ballNext = self.create_oval(0, 0, 0, 0, width=0, state="hidden")
self.level(1)
self.nextFrame()









share|improve this question






















  • You could try something like: def __init__(self, root, level): and then in the method self.level(level)
    – Richy
    Nov 20 at 9:52












  • ok then i start the game with this ? game = Game(root, level) root.mainloop()
    – Pixi
    Nov 20 at 9:58












  • You put something like self.level = input("Which level to play?") wherever you switch between levels.
    – MisterMiyagi
    Nov 20 at 9:58










  • @MisterMiyagi it doesn't work, told me that game is no defined
    – Pixi
    Nov 20 at 10:01










  • With the code you have provided, it is only possible to give you hints. There is no way anybody here can know what your program does when and how. You have to integrate it into your program yourself.
    – MisterMiyagi
    Nov 20 at 10:10
















0














I developed a little to learn Python.

This one has a level editor. I would like users to have direct access to the level they have created by entering the corresponding number. No interface needs, just an input.

For now the game starts directly at level 1 with the self.level (1), I do not know where to put my input so that the 1 is replaced by the entered value.

Thank you in advance for the help you could provide!



Here is my code :



This method initializes some attributes: the ball, the bar...



def __init__(self, root):
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
self.pack()
self.timeContainer = self.create_text(self.screenWidth/2, self.screenHeight*4/5, text="00:00:00", fill="#bdc3c7", font=("Arial", 15), justify="center")
self.shield = self.create_rectangle(0, 0, 0, 0, width=0)
self.bar = self.create_rectangle(0, 0, 0, 0, fill="#7f8c8d", width=0)
self.ball = self.create_oval(0, 0, 0, 0, width=0)
self.ballNext = self.create_oval(0, 0, 0, 0, width=0, state="hidden")
self.level(1)
self.nextFrame()









share|improve this question






















  • You could try something like: def __init__(self, root, level): and then in the method self.level(level)
    – Richy
    Nov 20 at 9:52












  • ok then i start the game with this ? game = Game(root, level) root.mainloop()
    – Pixi
    Nov 20 at 9:58












  • You put something like self.level = input("Which level to play?") wherever you switch between levels.
    – MisterMiyagi
    Nov 20 at 9:58










  • @MisterMiyagi it doesn't work, told me that game is no defined
    – Pixi
    Nov 20 at 10:01










  • With the code you have provided, it is only possible to give you hints. There is no way anybody here can know what your program does when and how. You have to integrate it into your program yourself.
    – MisterMiyagi
    Nov 20 at 10:10














0












0








0







I developed a little to learn Python.

This one has a level editor. I would like users to have direct access to the level they have created by entering the corresponding number. No interface needs, just an input.

For now the game starts directly at level 1 with the self.level (1), I do not know where to put my input so that the 1 is replaced by the entered value.

Thank you in advance for the help you could provide!



Here is my code :



This method initializes some attributes: the ball, the bar...



def __init__(self, root):
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
self.pack()
self.timeContainer = self.create_text(self.screenWidth/2, self.screenHeight*4/5, text="00:00:00", fill="#bdc3c7", font=("Arial", 15), justify="center")
self.shield = self.create_rectangle(0, 0, 0, 0, width=0)
self.bar = self.create_rectangle(0, 0, 0, 0, fill="#7f8c8d", width=0)
self.ball = self.create_oval(0, 0, 0, 0, width=0)
self.ballNext = self.create_oval(0, 0, 0, 0, width=0, state="hidden")
self.level(1)
self.nextFrame()









share|improve this question













I developed a little to learn Python.

This one has a level editor. I would like users to have direct access to the level they have created by entering the corresponding number. No interface needs, just an input.

For now the game starts directly at level 1 with the self.level (1), I do not know where to put my input so that the 1 is replaced by the entered value.

Thank you in advance for the help you could provide!



Here is my code :



This method initializes some attributes: the ball, the bar...



def __init__(self, root):
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
self.pack()
self.timeContainer = self.create_text(self.screenWidth/2, self.screenHeight*4/5, text="00:00:00", fill="#bdc3c7", font=("Arial", 15), justify="center")
self.shield = self.create_rectangle(0, 0, 0, 0, width=0)
self.bar = self.create_rectangle(0, 0, 0, 0, fill="#7f8c8d", width=0)
self.ball = self.create_oval(0, 0, 0, 0, width=0)
self.ballNext = self.create_oval(0, 0, 0, 0, width=0, state="hidden")
self.level(1)
self.nextFrame()






python python-3.x






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 9:50









Pixi

84




84












  • You could try something like: def __init__(self, root, level): and then in the method self.level(level)
    – Richy
    Nov 20 at 9:52












  • ok then i start the game with this ? game = Game(root, level) root.mainloop()
    – Pixi
    Nov 20 at 9:58












  • You put something like self.level = input("Which level to play?") wherever you switch between levels.
    – MisterMiyagi
    Nov 20 at 9:58










  • @MisterMiyagi it doesn't work, told me that game is no defined
    – Pixi
    Nov 20 at 10:01










  • With the code you have provided, it is only possible to give you hints. There is no way anybody here can know what your program does when and how. You have to integrate it into your program yourself.
    – MisterMiyagi
    Nov 20 at 10:10


















  • You could try something like: def __init__(self, root, level): and then in the method self.level(level)
    – Richy
    Nov 20 at 9:52












  • ok then i start the game with this ? game = Game(root, level) root.mainloop()
    – Pixi
    Nov 20 at 9:58












  • You put something like self.level = input("Which level to play?") wherever you switch between levels.
    – MisterMiyagi
    Nov 20 at 9:58










  • @MisterMiyagi it doesn't work, told me that game is no defined
    – Pixi
    Nov 20 at 10:01










  • With the code you have provided, it is only possible to give you hints. There is no way anybody here can know what your program does when and how. You have to integrate it into your program yourself.
    – MisterMiyagi
    Nov 20 at 10:10
















You could try something like: def __init__(self, root, level): and then in the method self.level(level)
– Richy
Nov 20 at 9:52






You could try something like: def __init__(self, root, level): and then in the method self.level(level)
– Richy
Nov 20 at 9:52














ok then i start the game with this ? game = Game(root, level) root.mainloop()
– Pixi
Nov 20 at 9:58






ok then i start the game with this ? game = Game(root, level) root.mainloop()
– Pixi
Nov 20 at 9:58














You put something like self.level = input("Which level to play?") wherever you switch between levels.
– MisterMiyagi
Nov 20 at 9:58




You put something like self.level = input("Which level to play?") wherever you switch between levels.
– MisterMiyagi
Nov 20 at 9:58












@MisterMiyagi it doesn't work, told me that game is no defined
– Pixi
Nov 20 at 10:01




@MisterMiyagi it doesn't work, told me that game is no defined
– Pixi
Nov 20 at 10:01












With the code you have provided, it is only possible to give you hints. There is no way anybody here can know what your program does when and how. You have to integrate it into your program yourself.
– MisterMiyagi
Nov 20 at 10:10




With the code you have provided, it is only possible to give you hints. There is no way anybody here can know what your program does when and how. You have to integrate it into your program yourself.
– MisterMiyagi
Nov 20 at 10:10












1 Answer
1






active

oldest

votes


















0














The method you posted is an initializer aka constructor. It is generally discouraged to do too much work in it. I usually only assign fields, and maybe call some simple methods. You definitely shouldn't ask for user input in the constructor but rather pass parameters to it. You didn't name your class so i'll name it myself:



class Some:
def __init__(self, root, level):
# all your stuff
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
# ...
self.root = root
self.level = level

# outside your class, where you instantiate it.
level = input('Which level?')
newsome = Some(root, level)





share|improve this answer





















  • thank you, i did this def level(self, level): self.reset() self.levelNum = input("Wich lvl") self.bricks = and it's work. Thanks a lot for your help everyone !
    – Pixi
    Nov 20 at 10:20













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390271%2finput-level-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The method you posted is an initializer aka constructor. It is generally discouraged to do too much work in it. I usually only assign fields, and maybe call some simple methods. You definitely shouldn't ask for user input in the constructor but rather pass parameters to it. You didn't name your class so i'll name it myself:



class Some:
def __init__(self, root, level):
# all your stuff
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
# ...
self.root = root
self.level = level

# outside your class, where you instantiate it.
level = input('Which level?')
newsome = Some(root, level)





share|improve this answer





















  • thank you, i did this def level(self, level): self.reset() self.levelNum = input("Wich lvl") self.bricks = and it's work. Thanks a lot for your help everyone !
    – Pixi
    Nov 20 at 10:20


















0














The method you posted is an initializer aka constructor. It is generally discouraged to do too much work in it. I usually only assign fields, and maybe call some simple methods. You definitely shouldn't ask for user input in the constructor but rather pass parameters to it. You didn't name your class so i'll name it myself:



class Some:
def __init__(self, root, level):
# all your stuff
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
# ...
self.root = root
self.level = level

# outside your class, where you instantiate it.
level = input('Which level?')
newsome = Some(root, level)





share|improve this answer





















  • thank you, i did this def level(self, level): self.reset() self.levelNum = input("Wich lvl") self.bricks = and it's work. Thanks a lot for your help everyone !
    – Pixi
    Nov 20 at 10:20
















0












0








0






The method you posted is an initializer aka constructor. It is generally discouraged to do too much work in it. I usually only assign fields, and maybe call some simple methods. You definitely shouldn't ask for user input in the constructor but rather pass parameters to it. You didn't name your class so i'll name it myself:



class Some:
def __init__(self, root, level):
# all your stuff
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
# ...
self.root = root
self.level = level

# outside your class, where you instantiate it.
level = input('Which level?')
newsome = Some(root, level)





share|improve this answer












The method you posted is an initializer aka constructor. It is generally discouraged to do too much work in it. I usually only assign fields, and maybe call some simple methods. You definitely shouldn't ask for user input in the constructor but rather pass parameters to it. You didn't name your class so i'll name it myself:



class Some:
def __init__(self, root, level):
# all your stuff
tk.Canvas.__init__(self, root, bg="#ecf0f1", bd=0, highlightthickness=0, relief="ridge", width=self.screenWidth, height=self.screenHeight)
# ...
self.root = root
self.level = level

# outside your class, where you instantiate it.
level = input('Which level?')
newsome = Some(root, level)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 10:02









Maiki Bodhisattva

787




787












  • thank you, i did this def level(self, level): self.reset() self.levelNum = input("Wich lvl") self.bricks = and it's work. Thanks a lot for your help everyone !
    – Pixi
    Nov 20 at 10:20




















  • thank you, i did this def level(self, level): self.reset() self.levelNum = input("Wich lvl") self.bricks = and it's work. Thanks a lot for your help everyone !
    – Pixi
    Nov 20 at 10:20


















thank you, i did this def level(self, level): self.reset() self.levelNum = input("Wich lvl") self.bricks = and it's work. Thanks a lot for your help everyone !
– Pixi
Nov 20 at 10:20






thank you, i did this def level(self, level): self.reset() self.levelNum = input("Wich lvl") self.bricks = and it's work. Thanks a lot for your help everyone !
– Pixi
Nov 20 at 10:20




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390271%2finput-level-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin